Php – Multiple File Upload with Progress Bar using PHP and HTML

cross-browserfile uploadhtmlPHP

I recently created a script that allows people to upload multiple files using a PHP backend and HTML form. I would like to implement a progress bar so that users do not click on the upload button twice while uploading multiple files. I would like to avoid using javascript or ajax if possible, but at the same time I would like cross browser compatibility.

here is my html form data:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose Course Code:
<select name="subject_list">
<option value="ACC 100">ACC 100</option>
<option value="ACC 406">ACC 406</option>
<option value="ECN 104">ECN 104</option>
<option value="ECN 204">ECN 204</option>
<option value="FIN 300">FIN 300</option>
<option value="GMS 200">GMS 200</option>
<option value="ITM 100">ITM 100</option>
<option value="ITM 301">ITM 301</option>
<option value="ITM 305">ITM 305</option>
<option value="ITM 330">ITM 330</option>
<option value="ITM 350">ITM 350</option>
<option value="ITM 407">ITM 407</option>
<option value="ITM 500">ITM 500</option>
<option value="ITM 501">ITM 501</option>
<option value="ITM 505">ITM 505</option>
<option value="ITM 600">ITM 600</option>
<option value="LAW 122">LAW 122</option>
<option value="SSH 105">SSH 105</option>
<option value="Other">Other</option>
</select><br>
Choose a file to upload (Max 500MB): <input name="rye_file[]" type="file" id="file_style" multiple />
<input type="submit" name="submit" value="Upload" />
</form> 
<form action="/logout.php">
<input type="submit" value="Logout">
</form>

and here is my backend:

<?php
$subject_list = $_POST['subject_list'];
$uploaddir = "/var/www/fixnode_website/content/Secure Login/Rye High/uploads/$subject_list";
$files=array();
$fdata=$_FILES['rye_file'];
if(is_array($fdata['name'])){
 for($i=0;$i<count($fdata['name']);++$i){
  $files[]=array(
   'name'     => $fdata['name'][$i],
   'tmp_name' => $fdata['tmp_name'][$i],
  );
 }
}
else $files[]=$fdata;

foreach ($files as $file) {
  // uploaded location of file is $file['tmp_name']
  // original filename of file is $file['name']
  $move_file = move_uploaded_file($file['tmp_name'], "$uploaddir/".$file['name']);
}
if($move_file){
   echo "File is valid, and was successfully uploaded to: $subject_list folder. Please wait, your browser will refresh in 5-10 seconds!";
   header('Refresh: 10; URL=/index.php');
  } 
  else {
     echo "Upload failed";
 }
?>

Best Answer

It might not be what you want, but I'd suggest you try

  1. uploadify http://www.uploadify.com [free] , there is also an html5 version. Sometimes, I try not to reinvent the wheels.
  2. If you concerned about the fee for uploadify, how about blueimp http://blueimp.github.com/jQuery-File-Upload/
  3. Like HTML5 so much, try http://www.igloolab.com/jquery-html5-uploader/ (You'd pay for this one with a Tweet or a Facebook post. How great is that?)
  4. A few other options: http://www.fyneworks.com/jquery/multiple-file-upload/
  5. Valums: https://github.com/valums/file-uploader (fine_uploader available for $15 one time pay) - makes sense.

Please note that you'd have to make use of Jquery, if you okay with that.