Monday, April 7, 2014

PHP, upload multiple files and add progress bar

 The difference between upload one file and multiple files in PHP is that we put array in name in
input, example, for upload a single file
 <input type="file"  name="file_single">
for upload multiple files, add [] in name, example
<input type="file" name="file_array[]">
 Complete example for uploading multiple files in PHP:
<!DOCTYPE html> 
 <meta charset="UTF-8">
<form action="upload.php" method="post" enctype="multipart/form-data">
 <p><input type="file" name="file_array[]">
 <input type="submit" value="Upload all files">

<?php /
 $name_array = $_FILES['file_array']['name']; 
$tmp_name_array = $_FILES['file_array']['tmp_name']; 
 $type_array = $_FILES['file_array']['type'];
 $size_array = $_FILES['file_array']['size']; 
$error_array = $_FILES['file_array']['error']; 
for($i = 0; $i < count($tmp_name_array); $i++){
 if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i]))
{ echo $name_array[$i]." upload is complete<br>"; }
 else {
 echo "move_uploaded_file function failed for ".$name_array[$i]."<br>"; } }
 } ?>

About  add upload progress bar:
Video: File Upload Progress Bar Meter Tutorial HTML5 Ajax PHP


No comments:

Post a Comment