上傳多個文件

可以對 input 域使用不同的 name 來上傳多個文件。

PHP 支持同時上傳多個文件并將它們的信息自動以數(shù)組的形式組織。要完成這項功能,需要在 HTML 表單中對文件上傳域使用和多選框與復(fù)選框相同的數(shù)組式提交語法。

示例 #1 上傳多個文件

<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>

當(dāng)以上表單被提交后,數(shù)組 $_FILES['userfile']$_FILES['userfile']['name']$_FILES['userfile']['size'] 將被初始化。

例如,假設(shè)名為 /home/test/review.html/home/test/xwp.out 的文件被提交,則 $_FILES['userfile']['name'][0] 的值將是 review.html,而 $_FILES['userfile']['name'][1] 的值將是 xwp.out。類似的,$_FILES['userfile']['size'][0] 將包含文件 review.html 的大小,依此類推。

此外也同時設(shè)置了 $_FILES['userfile']['name'][0], $_FILES['userfile']['tmp_name'][0]$_FILES['userfile']['size'][0] 以及 $_FILES['userfile']['type'][0]。

警告

As of PHP 5.2.12, the max_file_uploads configuration setting acts as a limit on the number of files that can be uploaded in one request. You will need to ensure that your form does not try to upload more files in one request than this limit.