PHP – Multiple File Upload on server

The given PHP example helps you to upload the multiple files on server at once.


<?php

$file_to_upload = 5;
$file_dir  = "./"; // directory where you want to upload the files, and don't forget to CHMOD 777 to this folder
if ($_POST) {
  for ($i=0;$i<$file_to_upload;$i++) {
   if (trim($_FILES['myfiles']['name'][$i])!="") {
     $newfile = $file_dir.$_FILES['myfiles']['name'][$i];
     move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
     $j++;
   }
  }
}
if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
print "<form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$file_to_upload;$i++) {
  print "<input type='file' name='myfiles[]' size='30'><br>";
}
print "<input type='submit' name='action' value='Upload'>";
print "</form>";
?>

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...