Level 50
The value of $file->getClientMimeType() comes from the browser and isn't reliable. Check what $file->getMimeType() returns.
I'm having trouble validating file types. Even though I've used dd($mimeType) to confirm that my file type is correctly application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, when I try to upload the file, it still fails validation ($validator->fails()). Can anyone offer any advice, here is my code
$file = $request->file('file');
$mimeType = $file->getClientmimeType();
$validateArr = [
'file' => 'mimetypes:application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream'
];
Log::info('Import Create Intent Evaluation : Mime Type 1 : ' . $mimeType);
$validator = Validator::make($request->all(), $validateArr, [
'file.mimetypes' => 'Chỉ hỗ trợ file có định dạng .xls, .xlsx'
]);
dd($mimeType);
if ($validator->fails()) {
throw new ValidationException($validator);
}
Please or to participate in this conversation.