上傳多個檔案

上傳多個檔案

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

PHP 支援同時上傳多個檔案並將它們的資訊自動以陣列的形式組織。要完成這項功能,需要在 HTML 表單中對檔案上傳域使用和多選框與覈取方塊相同的陣列式提交語法。

示例 #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>

當以上表單被提交后,陣列 $_FILES['userfile']$_FILES['userfile']['name']$_FILES['userfile']['size'] 將被初始化。

例如,假設名為 /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 的大小,依此類推。

此外也同時設定了 $_FILES['userfile']['name'][0]$_FILES['userfile']['tmp_name'][0]$_FILES['userfile']['size'][0] 以及 $_FILES['userfile']['type'][0]

警告

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.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *