按ctrl同时选中多个文件同时上传,结果只有最后一个被选中的文件被上传,请问什么原因
名字改为数组形式
<form action="" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="upload[]" type="file" multiple /><br />
<input type="submit" value="Send files" />
</form>
<?php
print_r($_FILES["upload"]);
?>
保存文件
// Count # of uploaded files in array
$total = count($_FILES['upload']['name']);
// Loop through each file
for($i=0; $i<$total; $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
}
}
}
一、input:file属性
属性值有以下几个比较常用:
accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表。
multiple:是否可以选择多个文件,多个文件时其value值为第一个文件的虚拟路径。
传送门:https://blog.csdn.net/hyd19931002/article/details/78320503
是因为你的name都是myfile1 你换成myfile1[] 数组的形式就可以了
name属性改成数组