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.
The validate method accepts an incoming HTTP request and a set of validation rules. If the validation rules pass, your code will keep executing normally; however, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user.
confirmed. The field under validation must have a matching field of foo_confirmation . For example, if the field under validation is password , a matching password_confirmation field must be present in the input.
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?
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