Sunday, March 5, 2017

Laravel image upload validation

I am trying to validate uploaded files using laravel validation but am having issues.

Here is my code:

$this->validate($request, [
        'image' =>'mimetypes:image/jpeg,image/png,image/gif',

        ]);

        $avatar = $request->file('image');

        $fileName = time(). '.' . $avatar->getClientOriginalExtension();
        Image::make($avatar)->resize(300,300)->save( public_path('uploads/avatar/' . $fileName));

        $user = Auth::user();
        $user->avatar = $fileName;
        $user->save();

The issue is when I use a bmp file, I get this error: Gd error

I am using the Intervention image package. I would rather not switch to the imagick driver.

Any ideas?



via John

Advertisement