0

I'm trying to integrate Intervention/Image into my laravel project to create a thumbnail upon uploading an image.

The image upload itself works fine, it doesn't seem to have any issue recognizing Intervention itself.

Below is the code block. The error seems to happen on the line with the save statement, I'm able to die and dump the contents of $img after it's set.

$file = $request->file('image');
$name = md5($file->getClientOriginalName() . time());
$extension = $file->getClientOriginalExtension();
$fileName =  $name . '.' . $extension;
$file->move('./uploads/images/', $fileName);

$img = Image::make($file)->fit(300);
$img->save('/uploads/thumbnails/' . $name, 60, 'jpg');

This is the error I'm getting:

SplFileInfo::getSize(): stat failed for /private/var/folders/87/p5x7mgy914qg9ytf2zccc6q00000gn/T/php3lshFS

After some searching I've found that this could be related to file size upload limits, but I've altered my php.ini file (all of this is local btw) to accept 20MB files and the file I'm trying to upload is less than 100kb. I've also reset both php through homebrew and apache. Still getting the error.

Is there any glaringly obvious issues in my use of Intervention? I'll happily provide more info, this is in the store function in one of my controllers btw.

1
  • The error message doesn't seem to reflect $fileName location (/uploads/images). Maybe $file still refers to old location of the file (which already moved)? Commented Oct 4, 2019 at 2:52

1 Answer 1

0

Untested, but I do it like this:

    public function thumbnail(Request $request){
        $thumbDir= storage_path('app/public').'/uploads/thumbnails/';
        $file = $request->file('image');
        $filename = md5($file->getClientOriginalName() . time()).'.jpg';
        // $name = md5($file->getClientOriginalName() . time());
        // $extension = $file->getClientOriginalExtension();
        // $fileName =  $name . '.' . $extension;
        // $file->move('./uploads/images/', $fileName);
        Image::make($file)->encode('jpg', 60)->fit(300, null, function ($c) {
            $c->aspectRatio();
            $c->upsize();
        })->save($thumbDir . $filename);
        return back()->with('success','The Image Has Been Added.');
    }

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Glad I could help. Please click to accept it as the correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.