單個的input type="file"表單也是可以實現多圖片上傳的
代碼如下:
<form action="manypic.php" method="post" enctype="multipart/form-data"> <input type="file" name="manypic[]" multiple> <input type="submit"> </form>
這里要給file表單加上一個multiple屬性 multiple="multiple"也可以
name的屬性值后面要加上[]這樣就可以了 print_r($_FILES)可得到如下信息:
Array ( [manypic] => Array ( [name] => Array ( [0] => 1.png [1] => bg.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => D:\xampp\tmp\php8C53.tmp [1] => D:\xampp\tmp\php8C54.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 44113 [1] => 325257 ) ) )
這里我上傳的是兩張圖片
另外你也可以提交多個input type="file"上傳域,代碼如下:
<form action="manypic.php" method="post" enctype="multipart/form-data"> <input type="file" name="pic1"> <input type="file" name="pic2"> <input type="submit"> </form>
php頁面的print_r的打印結果:
Array
(
[pic1] => Array ( [name] => bg.jpg [type] => image/jpeg [tmp_name] => D:\xampp\tmp\phpF661.tmp [error] => 0 [size] => 325257 ) [pic2] => Array ( [name] => 1.png [type] => image/png [tmp_name] => D:\xampp\tmp\phpF671.tmp [error] => 0 [size] => 44113 ) )