Infolinks

Breaking

Adsense

Thursday, April 28, 2016

UPLOAD MULTIPLE FILES USING PHP AND MYSQLI

Good day guys! I got new article for you to learn new things that you can apply later on future projects. This time will allow you to upload multiple files using PHP and MySQLi. This program is made of bootstrap but got it modified for you to easily understand the code more.

Before you forget, import the database called elearning. You can download it from the link below. It contains two (2) tables; teacher and upload. You will be needing teacher table to be able to register and login to the system. While the upload table will store all file names of uploaded files. Uploaded images will be stored on the dist/uploads directory.

HTML Code for multiple upload

<form role="form" method="post" action="upload.php" enctype="multipart/form-data">
<div class="form-group">
<div id="more" style="">
<label>Upload File/s</label>
<input type="file" class="postbox-file-upload multi" name="files[]" multiple="multiple" required>
<i>Upload multiple files by selecting multiple files.</i>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary pull-right" name="post">Save</button>
</div>
</form>

Don’t forget the highlighted codes above. The enctype="multipart/form-data" will allow you to upload files such as image, or any file type. The name="files[]" multiple="multiple" from the input type=”file” will allow you to select multiple files by pressing the ctrl key + click files.
Name should be in array form files[] since it can store multiple files on just one (1) name.

foreach ($_FILES['files']['name'] as $f => $name) To access the array values one by one and save it on the table, we are going to use the looping statement which is the foreach loop. Each value will be stored one by one in the $name variable and store it in the upload table. Remember, in this program, only files names are stored in the upload table. Files are being copied to the dist/uploads folder. 

SAMPLE OUTPUT OF MULTIPLE UPLOAD IN PHP





DOWNLOAD UPLOAD MULTIPLE FILES

Database name: elearning
Username: lee
Password: 1

UPLOAD MULTIPLE FILES USING PHP AND MYSQLI

No comments:

Post a Comment

Adbox