Upload File Email Web Form
DHTML-Ajax-popup-contact-form_5.png' alt='Upload File Email Web Form' title='Upload File Email Web Form' />Create file upload forms for Google Drive and receive files from anyone in your Google Drive. This article explains how to send Asynchronous Mail with multiple file attachments and multiple file uploads using SmtpClient. SendAsync. Multiple File Upload with PHP and My. SQLDownload Now. No Live Demo. In this tutorial we will make a multi file Upload with PHP system with verification for the file extension and size, to make a secure upload and save the file information into a My. SQL database. The system will automatically rename the file name if needed. For this tutorial we will make an image upload system. This can be used to upload images, PDFs, Docs or any file types make sure you do change in the script. If are new to file uploading you can check our article on Simple File Upload with PHP, to get started with basic. Motogp Race Games here. The HTMLThis is a simple HTML forum, there wont be any styles, since wer focusing on the PHP upload. POST enctypemultipartform data. Make sure to make add enctypemultipartform data ,typefile and most importantly namefiles to enable multi files selection possible. Upload File Email Web Form' title='Upload File Email Web Form' />PHPMoving on to the PHP codes. FILES in the if condition to make sure some file is selected and we are good to go with the upload. FILES will contain the information of each file, but when more that one file are selected it will have the details of each file enclosed inside another array. To see how data is stored in array refer our article on Simple File Upload with PHP. To access them we will be using foreachforeach loop. FILESfilestmpname as key tmpname. FILESfilesnamekey. FILESfilessizekey. Upload File Email Web Form' title='Upload File Email Web Form' />FILESfilestmpnamekey. FILESfilestypekey. Now to make the verification part. First we will make an array with the allowed extensions in it. As we are making an image upload, we need to allow only the image extensions i. JPEG, PNG. etc. You can add the appropriate extensions that you need. To get the extension of the uploaded file we will use the file name not file Type, to get the extension we will use PHP explode end. Extensions can also be in UPPER case or LOWER case to overcome the problem we will get them converted into lower case or upper case as you mentioned in the extensions array. Using PHP inarray to verify if the uploaded file is allowed or not, its almost done. FILESimagenamekey. FILESimagenamekey. To limit the upload file size, FILESimagesize is to be used to get the file size. FILESimagesizekey 2. File size must be less tham 2 MB. SQLThat is all with upload part, the files are ready to be moved to a folder and store the file details in My. SQL tables if necessary. In this tutorial we use a My. SQL table with 4 rows. CREATE TABLE uploaddata. ID int5 NOT NULL AUTOINCREMENT. USERCODE int4 unsigned zerofill NOT NULL. FILENAME varchar2. NOT NULL. FILESIZE varchar2. NOT NULL. FILETYPE varchar2. NOT NULL. PRIMARY KEY ID. USERCODE is unique for each user if you have a user based application or any unique ID that can identify each items. INSERT into uploaddata EMPCODE,FILENAME,FILESIZE,FILETYPE VALUEScodes,filename,filesize,filetype. Make sure that the query is not executed unless the errors array is empty. Moving the Files. File uploaded will be allocated space in the temporary location as mentioned in the php. It is necessary to move the file from the temporary location to another in order to use it again. You can get the file moved to another location using moveuploadedfile, in here we will move it to an images folder, make sure the directory exists, since moveuploadedfile cannot create a directory. So it recommended to verify for existence of directory. If you plan to create a directory for each user, you can use mkdirDIR NAME,PERMISION. To Rename the file. Users can create a problem if there exists another file with same name, since moveuploadedfile cannot move the file if another file existed. You can get the file renamed or rename all the files uploaded with a series number which can prevent this problem completely. With renameOLDFILENAME,NEWFILENAME. OLDFILEPATH file name with extension location and NEWFILENAME new name. Check if a file of same name exist. Winding. You can use the following codes to upload files of any size type, make sure you have enough space on the server. The complete code for the project. FILESfiles. FILESfilestmpname as key tmpname. FILESfilesnamekey. FILESfilessizekey. FILESfilestmpnamekey. FILESfilestypekey. File size must be less than 2 MB. INSERT into uploaddata USERID,FILENAME,FILESIZE,FILETYPE VALUESuserid,filename,filesize,filetype. Create directory if it does not exist. Success. lt form action methodPOST enctypemultipartform data. Download Now. No Live Demo.