Bijesh Shrestha
Bijesh Shrestha

Reputation: 371

jpeg file not recognized as image in laravel

I have made a validation for image field as

'avatar' => 'nullable|image|mimes:jpeg,png,jpg|max:1000',

it works for png image but fails if i upload jpeg image with message The avatar must be an image. Any thoughts? Here is form view

    {!! Form::open(['route'=>['admin.myprofile.update',$admin->id],'method'=>'put','files'=>true]) !!}
...
            {!! Form::file('avatar', ['class' => 'dropify btn-warning','data-default-file'=>$admin->avatar?asset($admin->avatar):'']) !!}
..
    {!! Form::close() !!}

Upvotes: 0

Views: 817

Answers (2)

yasir gakhar
yasir gakhar

Reputation: 133

The image validator is kind of buggy here. Avoid using this validator. In the accepted answer even if you remove the mimes types validator and use the image validator only as following

'avatar' => 'nullable|image|max:1000'

Then for some jpeg images, it will work fine but for most images, it will not work.

Correction for the accepted answer. There is a typo there as mimes: is repeated twice. Bellow is the corrected code

'avatar' => 'nullable|mimes:jpeg,jpg,png,gif|max:1000'

Upvotes: 0

xuan hung Nguyen
xuan hung Nguyen

Reputation: 398

I think your rule validation is overlap each other you can change it to this and see the result:

'avatar' => 'nullable|mimes:mimes:jpeg,jpg,png,gif|max:1000'

Upvotes: 1

Related Questions