Home >Backend Development >PHP Problem >How to upload multiple files at the same time in php
You can use different names for the input field to upload multiple files.
PHP supports uploading multiple files at the same time and automatically organizes their information in the form of arrays. To accomplish this functionality, you need to use the same array submission syntax for the file upload field in the HTML form as for checkboxes and checkboxes.
Note:(Recommended learning: PHP programming from entry to proficiency)
Support for multiple file uploads is in PHP 3.0 Added in version .10.
Upload multiple files
<form action="file-upload.php" method="post" enctype="multipart/form-data"> Send these files:<br /> <input name="userfile[]" type="file" /><br /> <input name="userfile[]" type="file" /><br /> <input type="submit" value="Send files" /> </form>
When the above form is submitted, the array $_FILES['userfile'], $_FILES['userfile']['name' ] and $_FILES['userfile']['size'] will be initialized ($HTTP_POST_FILES in versions prior to PHP 4.1.0).
If register_globals is set to on, global variables related to file upload will also be initialized. All these submissions will be stored in a numerically indexed array.
For example, assuming that files named /home/test/review.html and /home/test/xwp.out are submitted, then $_FILES['userfile']['name'][0] The value will be review.html and the value of $_FILES['userfile']['name'][1] will be xwp.out.
Similarly, $_FILES['userfile']['size'][0] will contain the size of the file review.html, and so on.
In addition, $_FILES['userfile']['name'][0], $_FILES['userfile']['tmp_name'][0], $_FILES['userfile'] are also set. ['size'][0] and $_FILES['userfile']['type'][0].
The above is the detailed content of How to upload multiple files at the same time in php. For more information, please follow other related articles on the PHP Chinese website!