PHP Multiple File Upload


/ Published in: PHP
Save to your folder(s)

1. Edit the html form 'action' to point to your PHP page that handles the upload.
2. Create the php page with the code below
3. Define Paths in PHP lines: 3 , 4 of php file
4. Create matching folder to paths in #3 on server.
5. chmod that folder 777
6. Tweak to your liking.


Copy this code and paste it in your HTML
  1. use this html for the upload form:
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  7. <title>File Upload</title>
  8. <style type="text/css">
  9. body {font-family:Lucida Grande, "Lucida Sans", arial; font-size:1.3em; color:#555;}
  10. </style>
  11. </head>
  12.  
  13. <body>
  14. <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  15. <tr>
  16. <form action="upload_handle.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  17. <td><table width="100%" border="0" cellpadding="8" cellspacing="8" bgcolor="#FFFFFF">
  18. <tr>
  19. <td><strong>Multiple File Upload:<br /><span style="font-size:70%;">(*you dont have to upload more than one.)</span></strong></td>
  20. </tr>
  21. <tr>
  22. <td> File One <br />
  23. <input name="ufile[]" type="file" id="ufile[]" size="50" />
  24. </td>
  25. </tr>
  26. <tr>
  27. <td>File Two<br />
  28. <input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
  29. </tr>
  30. <tr>
  31. <td align="center"><input type="submit" name="Submit" value="Upload" /></td>
  32. </tr>
  33. </table></td>
  34. </form>
  35. </tr>
  36. </table>
  37. </body>
  38. </html>
  39.  
  40. --------------------------
  41.  
  42. php
  43.  
  44. <?php
  45. // define your paths below eg uploaded_files chmod that dir 777
  46. $path1= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][0];
  47. $path2= "uploaded_files/".$HTTP_POST_FILES['ufile']['name'][1];
  48.  
  49. // copy files to server
  50. copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
  51. copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
  52.  
  53. // get sizes
  54. $filesize1=$HTTP_POST_FILES['ufile']['size'][0];
  55. $filesize2=$HTTP_POST_FILES['ufile']['size'][1];
  56.  
  57. // output file info upon success or throw error
  58. if($filesize1 != 0){
  59. echo "File Name : ".$HTTP_POST_FILES['ufile']['name'][0]." was uploaded <br />";
  60. echo "File Size : ".$HTTP_POST_FILES['ufile']['size'][0]."<br />";
  61. echo "File Type : ".$HTTP_POST_FILES['ufile']['type'][0]."<br /><br />";
  62. }else{
  63. echo "No File Uploaded <br /><br />";
  64. }
  65. // output file info upon success or throw error
  66. if($filesize2 != 0){
  67. echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<br />";
  68. echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<br />";
  69. echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<br />";
  70. }else{
  71. echo "2nd File Not Uploaded <br /><br />";
  72. }
  73.  
  74. ?>

URL: http://www.thatgrafix.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.