PHP Manual
Prev | Chapter 18. Handling file uploads | Next

# Uploading multiple files

It is possible to upload multiple files simultaneously and have the information organized automatically in arrays for you. To do so, you need to use the same array submission syntax in the HTML form as you do with multiple selects and checkboxes:

> Note: Support for multiple file uploads was added in version 3.0.10.

Example 18-2. Uploading multiple forms
      1
      2 <form action="file-upload.html" method="post" enctype="multipart/form-data">
      3   Send these files:<br>
      4   <input name="userfile[]" type="file"><br>
      5   <input name="userfile[]" type="file"><br>
      6   <input type="submit" value="Send files">
      7 </form>
      8

When the above form is submitted, the arrays `$userfile`, `$userfile_name`, and `$userfile_size` will be formed in the global scope (as well as in $HTTP_POST_VARS). Each of these will be a numerically indexed array of the appropriate values for the submitted files.

For instance, assume that the filenames `/home/test/review.html` and `/home/test/xwp.out` are submitted. In this case, `$userfile_name[0]` would contain the value `review.html`, and `$userfile_name[1]` would contain the value `xwp.out`. Similarly, `$userfile_size[0]` would contain `review.html`'s filesize, and so forth.

Prev | Home | Next
Common Pitfalls | Up | PUT method support