$this->validate($request,
[
'file'=> 'required|mimes:xlsx'
]);
当我尝试上传.xlsx文件时,验证程序失败。
答案 0 :(得分:1)
您应该尝试以下代码:
$validator = Validator::make(
[
'file' => $request->file,
'extension' => strtolower($request->file->getClientOriginalExtension()),
],
[
'file' => 'required',
'extension' => 'required|in:xlsx,xls',
]
);
您还可以从控制器中查看:
if(Input::hasFile('import_file')){
$uploadedFileMimeType = Input::file('import_file')->getMimeType();
$mimes = array('application/excel','application/vnd.ms-excel','application/vnd.msexcel');
if(in_array($_FILES['import_file']['type'], $mimes)){
//True
} else{
return redirect()->back()->withInput()->withFlashDanger("Please select Only Excel File");
}
}