1 回答

TA貢獻(xiàn)1788條經(jīng)驗 獲得超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 關(guān)注
- 102 瀏覽
添加回答
舉報