Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LSheNNawY's avatar

validation images

Hi there, I'm trying to validate two files inputs one for a logo and the other for an icon,

1- added the enctype="multipart/form-data" to the form.

2- validation rules for these inputs are:[ 'logo' => 'image|mimes:jpeg, jpg, bmp, png', 'icon'=> 'image|mimes:ico', ]

3- when I try to upload a logo of the type png, it returns an error says "The Logo must be a file of type: jpeg, jpg, bmp, png."

4- when I try to upload an icon of the type ico it returns error says "The Icon must be an image."

0 likes
4 replies
Cronix's avatar
Cronix
Best Answer
Level 67

Try removing the spaces between the mime types in both places

'logo' => 'image|mimes:jpeg,jpg,bmp,png'

When a rule accepts parameters separated by commas, there can't be any spaces in between the values since it will explode() on commas to get the individual parameters and if they have spaces in it then it becomes " jpg" and " png" instead of "jpg" and "png". I don't think it runs trim() on the results.

Notice in the user guide how they don't have spaces: https://laravel.com/docs/5.6/validation#rule-mimes

'photo' => 'mimes:jpeg,bmp,png'

1 like
Cronix's avatar

But I don't know why you'd have both image and mimes in the same rule since your mime types are already covered by the image rule.

bobbybouwmann's avatar

Your mimes list should be without spaces as far as I know!

Also for images there is a separate validation rule called image, you don't need mimes anymore then ;)

Documentation: https://laravel.com/docs/5.6/validation#rule-image

The ico rule should work as far as I know! Are you sure that image is of the type image/x-icon?

LSheNNawY's avatar

Thanks you all, the problem was the spaces and the ico file only worked when i removed image rule @bobbybouwmann from icon attribute

Please or to participate in this conversation.