1.
<html> 請宣告成 HTML5 標準
<!doctype html>
<html>
2.
<form action="?mode=upload" method="post" enctype="multipart/form-data">
上傳檔案:<input type="file" name="upfile[]" multiple="true">
<input type="submit" value="上傳"><br>
</form>
3. 就可以出現如下的多選上傳
4. 收到的 $_FILES 會變成陣列
Array
(
[upfile] => Array
(
[name] => Array
(
[0] => 0cbc1598.jpg
[1] => 1p7R7jfl.jpg
[2] => 5.jpg
[3] => 66ea50105754c4cba20bbc9e00eaf0a6.png
[4] => 165.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
[2] => image/jpeg
[3] => image/png
[4] => image/jpeg
)
[tmp_name] => Array
(
[0] => /tmp/phpFFDfEU
[1] => /tmp/phpEhK3c6
[2] => /tmp/php9HNULh
[3] => /tmp/phpaZYMkt
[4] => /tmp/phpBHSHTE
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
)
[size] => Array
(
[0] => 14758
[1] => 93531
[2] => 18026
[3] => 86406
[4] => 76831
)
)
)
請注意陣列是在後面,所以使用的時候可以以其中一個 key 當頭
例如:
for($i=0 ; $i< count($_FILES['upload']['name']) ; i++)
{
echo $_FILES['upload']['name'][$i] . "<br>";
}
這樣就可以作到多檔上傳,拿到所有的上傳資料了