Mimes Validation not working correctly in Laravel
Make sure your form has an attribute enctype="multipart/form-data"
Also, if you use mimes validation the format must be 'mimes:jpeg,bmp,png' https://laravel.com/docs/5.6/validation#rule-mimes
You can read about the enctype attribute here : What does enctype='multipart/form-data' mean?
Muhammad
Updated on June 13, 2022Comments
-
Muhammad almost 2 years
My webpage contains a file for upload, and I want the file uploaded to only be either pdf, doc or docx.
My form tag also has enctype="multipart/form-data"
My html looks like:
<div id="cv_upload" class="row"> <div class="col-xs-12"> <input type="file" name='cv'> </div> </div>
The $rules array associated with this is as follows:
'cv' => 'mimes:application/pdf,application/doc,application/docx|required'
And finally my messages looks like:
'cv.required' => 'A selection for C.V. is required before proceeding.', 'cv.mimes' => 'CV must be of the following file type: pdf, doc or docx.'
The only problem with this is, even after I upload a pdf or doc, the message I receive is the one for required. I have no idea why this isn't working as expected. I also tried removing the 'application/' but that yields no success either. Please help.
-
Muhammad almost 7 yearsno luck :/ I put both but it still isn't able to work.
-
buryo over 4 yearsAdding the form attribute solved my problem, worth trying it out!