这是我用于上传多个文件的控制器代码,我正在从 Google Chrome 上的“邮递员”rest API 客户端传递密钥和值。我正在从邮递员添加多个文件,但只有一个文件正在上传。
public function post_files() {
$allowedExts = array("gif", "jpeg", "jpg", "png","txt","pdf","doc","rtf","docx","xls","xlsx");
foreach($_FILES['file'] as $key => $abc) {
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$filename= $temp[0];
$destinationPath = 'upload/'.$filename.'.'.$extension;
if(in_array($extension, $allowedExts)&&($_FILES["file"]["size"] < 20000000)) {
if($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
if (file_exists($destinationPath)) {
echo $filename." already exists. ";
} else {
$uploadSuccess=move_uploaded_file($_FILES["file"]["tmp_name"],$destinationPath);
if( $uploadSuccess ) {
$document_details=Response::json(Author::insert_document_details_Call($filename,$destinationPath));
return $document_details; // or do a redirect with some message that file was uploaded
// return Redirect::to('authors')
} else {
return Response::json('error', 400);
}
}
}
}
}
我也尝试过这段代码,但它返回了临时文件夹中文件的位置
$file = Input::file('file');
echo count($file);
并
echo count($_FILES['file']);
总是返回我 5.谁能告诉我为什么?
以及为什么foreach(Input::file('file') as $key => $abc)
给出错误无效参数