Validation on images if passing despite clear failures, why?

Viewed 37

I am using Laravel 5.7. I have a form with a file upload on it called logo. My form has the correct enctype (enctype="multipart/form-data").

I have the following rules against the logo field:

['required', 'image', 'dimensions:max_width=200,max_height=200']

If I try to upload something that isn't an image it fails, which is correct.

However, if I try to upload a 3000x3000px jpg this goes through without issue and the file is uploaded. It's as though my dimensions rule is being ignored.

Am I missing something?

2 Answers

I don't see anything wrong with your rule, it is as documented, but just in case something's wrong with the parser, have you tried using:

'image' => ['required', 'image', Rule::dimensions()->maxWidth(200)->maxHeight(200)]

Maybe try to use another format of validation like that:

$this->validate($request, [
    'image'=> 'required|image|dimensions:min_width=200,min_height=200',
]);

Good luck!

Related