1 回答
TA贡献1788条经验 获得超4个赞
那是因为您使用return,return将使您退出该功能,并且您只会获得上传的第一个项目。
一个简单的解决方法是:
if (!move_uploaded_file($_FILES["uploadedFile"]["tmp_name"][$i], $target_file)) {
return 0;
}
//更新2个解决方案的建议
public function upload() {
$file_count = count($_FILES['uploadedFile']['name']);
//$file_count = count($_FILES($file_post['name']));
// add a array to save the basename on each loop
$results = [];
for ($i = 0; $i<$file_count; $i++) {
// echo $file['uploadedFile']['name'][$index] . "\n";
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["uploadedFile"]["name"][$i]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
return 0;
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["uploadedFile"]["tmp_name"][$i], $target_file)) {
$results[] = basename($_FILES["uploadedFile"]["name"][$i]);
} else {
return 0;
}
}
}
//return all basename in one shot
return $results;
}
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报