Home  >  Article  >  Backend Development  >  php multiple file upload

php multiple file upload

伊谢尔伦
伊谢尔伦Original
2016-11-22 10:26:511048browse

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:

Support for multiple file uploads was added in PHP version 3.0.10.

Example #1 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 arrays $_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 files named /home/test/review.html and /home/test/xwp.out are submitted, the value of $_FILES['userfile']['name'][0] 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']['size' are also set at the same time. ][0] and $_FILES['userfile']['type'][0].


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn