首先向大家介绍一下html5中file的multiple属性
定义和用法
multiple 属性规定输入字段可选择多个值。如果使用该属性,则字段可接受多个值。
实例:
<form action=\"demo_form.asp\" method=\"get\">
Select images: <input type=\"file\" name=\"img\" multiple=\"multiple\" />
<input type=\"submit\" />
</form>
上面实例中的input file 可接受多个文件上传字段。
了解了html5中file的multiple属性,下面我们开始讲解使用html5实现多文件上传。
实例代码:
html:
<!DOCTYPE html>
<html>
<head>
< charset=\"UTF-8\">
</head>
<body>
<form action=\"my_parser.php\" method=\"post\" enctype=\"multipart/form-data\">
<p><input name=\"upload[]\" type=\"file\" multiple=\"multiple\" /></p>
<input type=\"submit\" value=\"Upload all files\">
</form>
</body>
</html>
php代码:
for($i=0; $i<count($_FILES[\'upload\'][\'name\']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES[\'upload\'][\'tmp_name\'][$i];
//Make sure we have a filepath
if ($tmpFilePath != \"\"){
//Setup our new file path
$newFilePath = \"./uploadFiles/\" . $_FILES[\'upload\'][\'name\'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
继续阅读与本文标签相同的文章
上一篇 :
中台产品面面观(一)
-
城市数字化后,新一代内生安全系统可全方位保护
2026-05-14栏目: 教程
-
谷歌也来“唱衰”5G,5G手机只会徒增功耗?为何这么说?
2026-05-14栏目: 教程
-
量子信息和量子技术白皮书合肥宣言在中科大发布
2026-05-14栏目: 教程
-
微信悄悄更新一新功能,来看看!
2026-05-14栏目: 教程
-
打破三大运营商垄断,第四大运营商终于来了!
2026-05-14栏目: 教程
