Reputation: 601
I have validation:
if ($request->hasFile('otherFiles')) {
$this->validate($request, [
'otherFiles' => 'mimes:image/jpeg'
]);
}
How can I add to this validation files type: DOC, DOCX, CSV, PDF, RTF, PNG, xlsx, XLS, TXT, BMP?
Upvotes: 0
Views: 2336
Reputation: 1322
'otherFiles.*' => 'mimes:jpeg,bmp,png'
for full mime type
'otherFiles.*' => 'mimetypes:image/jpeg,image/bmp,image/png'
for list of all mime types and their extensions mime types
Upvotes: 4
Reputation: 601
i have this code:
if ($request->hasfile('otherFiles')) {
$this->validate($request, [
'otherFiles' => 'required',
'otherFiles.*' => 'mimes:jpg,jpeg,bmp,png,doc,docx,csv,rtf,xlsx,xls,txt,pdf'
]);
foreach ($request->file('otherFiles') as $file) {
$extension = strtolower($file->getClientOriginalExtension());
$path = 'upload/other/';
$uniqueName = md5($file . time());
$file->move(public_path($path), $uniqueName . '.' . $extension);
}
}
and I have error: "otherFiles":["other files must file type image/jpeg."
Upvotes: 2