I am trying to validate an uploaded csv file with
$validator = Validator::make(
[
'file' => $file,
'extension' => strtolower($file->getMimeType()),
],
[
'file' => 'required|in:csv',
]
);
The validator fails on giving a valid csv file with message The file must be a file of type: csv.
The validator passes if i remove in:csv
.
Am i doing something wrong?
PS - $file
is available and of standard upload file type object(Symfony\Component\HttpFoundation\File\UploadedFile)
you can use required|mimes:csv,txt for validation csv file. Although is too late, validating the txt mime will allow ANY txt files, even any . sql file.
Try changing
$validator = Validator::make(
[
'file' => $file,
'extension' => strtolower($file->getMimeType()),
],
[
'file' => 'required|in:csv',
]
);
To
$validator = Validator::make(
[
'file' => $file,
'extension' => strtolower($file->getClientOriginalExtension()),
],
[
'file' => 'required',
'extension' => 'required|in:csv',
]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With