michaelp0730
1/19/2015 - 6:45 PM

Multiple File Upload (PHP)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>File Upload</title>
<style type="text/css">
body {font-family:Lucida Grande, "Lucida Sans", arial; font-size:1.3em; color:#555;}
</style>
</head>
 
<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <form action="upload_handle.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <td><table width="100%" border="0" cellpadding="8" cellspacing="8" bgcolor="#FFFFFF">
          <tr>
            <td><strong>Multiple File Upload:<br /><span style="font-size:70%;">(*you dont have to upload more than one.)</span></strong></td>
          </tr>
          <tr>
            <td> File One <br />
              <input name="ufile[]" type="file" id="ufile[]" size="50" />
            </td>
          </tr>
          <tr>
            <td>File Two<br />
              <input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
          </tr>
          <tr>
            <td align="center"><input type="submit" name="Submit" value="Upload" /></td>
          </tr>
        </table></td>
    </form>
  </tr>
</table>
</body>
</html>
 
--------------------------
 
php
 
<?php
// define your paths below eg uploaded_files chmod that dir 777
$path1= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][1];
 
// copy files to server
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
 
// get sizes
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
 
// output file info upon success or throw error
if($filesize1 != 0){
	echo "File Name : ".$HTTP_POST_FILES['ufile']['name'][0]." was uploaded <br />"; 
	echo "File Size : ".$HTTP_POST_FILES['ufile']['size'][0]."<br />"; 
	echo "File Type : ".$HTTP_POST_FILES['ufile']['type'][0]."<br /><br />"; 
		}else{
			echo "No File Uploaded <br /><br />";
		}
// output file info upon success or throw error
if($filesize2 != 0){
	echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<br />"; 
	echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<br />"; 
	echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<br />"; 
	}else{
		echo "2nd File Not Uploaded <br /><br />";
	}
 
?>