Laravel "Can't write image data to path ({$path})"

430 Views Asked by At

I create Laravel project on ubuntu 18.4.

I upload my project in /var/www/html/ and i upload images in home/sun/download/

after run this code:

$imageName = "thumb_{$size}.{$extension}";
$routePath = $url . '/products/' . $product->id . '/';

Image::make($file->path())->resize($size, null, function ($constraint) {
            $constraint->aspectRatio();
        })->save($routePath, $imageName);

Show this error:

"Can't write image data to path (/home/sun/download/products/2/)"

How to issue this problem?

1

There are 1 best solutions below

4
Emad Ha On

Permission issue, Have you tried using the Storage facade?

$Image->save(Storage::disk('your_disk')->path($routePath), $quality);

That's how i stored images in my situation

Image = Image::make($source);
$Image->getCore()->stripImage();

# Resize the image and save
$Image->fit($width, $height, function ($constraint) {
     $constraint->upsize();
});

return $Image->save(Storage::disk('public')->path($destination), $quality);