Facebook
Banner
XMPP JavaScript Library READ MORE

How to upload multiple files in PHP without using multiple file elements or flash

PHP, Sachin Puri, 2012-04-17 12:03:38

This is a very simple HTML5 + PHP code to upload multiple files without using multiple FILE elements or Flash or JavaScript. Here in this code two things are most important:

1. First is name of file input element, you have to give it a name with square brakets for example txtFiles[] so that it will work as a array of files for PHP

2. Second is multiple attribute used in file input element which gives input file element the power of selecting multiple files.

Other things are as usual.

Warning: This script is just for uploading multiple files, it dose not take care of security issues, please check file type, extension, size etc. before uploading files because this is essential from security point of view.

Please feel free to post any questions or comments. 

 

<?
if(isset($_POST['submit'])){
    for($i=0; $i<count($_FILES['txtFiles']['name']); $i++){
        move_uploaded_file($_FILES['txtFiles']['tmp_name'][$i],$_FILES['txtFiles']['name'][$i]);
    }
}
?>

<html>
<head>
    <title>How to upload multiple files in PHP</title> 
</head>
<body>
    <form method="post" enctype="multipart/form-data">
        <label>Files</label><input type="file" name="txtFiles[]" multiple/><input type="submit" name="submit" value="Upload"/>
    </form>
</body>
</html>

 

Add Your Comment
   
    Yes! I want to receive all comments by email

  by aman on 15-Jan-2015 06:34 pm
Thanxxxx friend
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by tab on 10-Jan-2014 01:06 am
i have multiple field in one form i need to upload 10 file after click a button add more one browse will come then i can add file also file name year same again if i click add more then again i can add one more details of file can u help me to about this script
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Sonu on 14-Sep-2013 11:09 pm
Thanks bro for the help. Previously i was using flash to upload multiple files.
  • Reply
  •  1 Like
  •  1 Dislike
  • Report
  by Rohit Kurmi on 20-Jul-2012 08:28 am
Very good job, It works on 3D Array(i.e $_FILES['txtFiles']'tmp_name'][$i]) concept.Thanks............:)
  • Reply
  •  5 Like
  •  2 Dislike
  • Report
  by afzal on 08-Jun-2012 05:03 pm
thank you very much sir.. !!! For This Easy Codes
  • Reply
  •  4 Like
  •  3 Dislike
  • Report