input type="file"多图片上传
单个的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
)
)