PHP8 上傳多個文件

2023-08-23 15:56 更新

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

PHP 支持同時上傳多個文件并將它們的信息自動以數(shù)組的形式組織。要完成這項(xiàng)功能,需要在 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]。

警告
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.


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號