Uploading multiple files

Multiple files can be uploaded using different name for input.

It is also 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 19-3. Uploading 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 $HTTP_POST_FILES['userfile'], $HTTP_POST_FILES['userfile']['name'], and $HTTP_POST_FILES['userfile']['size'] will be initialized. (As well as in $_FILES for PHP 4.1.0 or later. $HTTP_POST_VARS in PHP 3. When register_globals is on, globals for uploaded files are also initialized). 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, $HTTP_POST_FILES['userfile']['name'][0] would contain the value review.html, and $HTTP_POST_FILES['userfile']['name'][1] would contain the value xwp.out. Similarly, $HTTP_POST_FILES['userfile']['size'][0] would contain review.html's filesize, and so forth.

$HTTP_POST_FILES['userfile']['name'][0], $HTTP_POST_FILES['userfile']['tmp_name'][0], $HTTP_POST_FILES['userfile']['size'][0], and $HTTP_POST_FILES['userfile']['type'][0] are also set.