In Laravel5 I validate a picture with the following code:
public function rules() {
return [
'name' => 'required',
'pic' => 'required|mimes:jpeg,png',
];
}
It works for files with extensions filename.jpg
and filename.jpeg
but it doesn't for filename.JPG
.
However, it doesn't return wrong file extension but a missing file. Can anyone help?
Try this in your pic
rules:
'pic' => 'required|mimes:jpeg,jpg,png',
Had this problem and found that when you use mimes:
rule, you have to specify the extensions you want as valid i. e. you have to add both jpeg
and jpg
extension variations.
Use mimetypes:
rule with image/jpeg
that covers 3 extension variations for the jpeg format: jpg jpeg jpe
.
Use image
rule which covers jpeg, png, bmp, gif, or svg
including jpeg
's extension variations
More on the mimes
and mimetypes
rules: https://laravel.com/docs/5.5/validation#rule-mimetypes
All MIME types:
A full listing of MIME types and their corresponding extensions may be found at the following location: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
Try 'pic' => 'required|image'
and make sure your form has the enctype="multipart/form-data"
attribute.
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