Sunday, April 6, 2014

PHP, upload multiple files and progress bar




main.html
<!DOCTYPE html> 
<html>
 <head>
 <meta charset="UTF-8">
 </head> 
<body> 
<form action="upload.php" method="post" enctype="multipart/form-data">
 <p><input type="file" name="file_array[]">
 <input type="submit" value="Upload all files">
 </form> 
</body>
 </html>

upload.php
<?php /
 if(isset($_FILES['file_array'])){
 $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 upload progress bar, reference:
File Upload Progress Bar Meter Tutorial HTML5 Ajax PHP 
http://www.developphp.com/view.php?tid=1351

No comments:

Post a Comment