简体   繁体   中英

Intervention\Image\Exception\NotWritableException: Can't write image data to path

I tried to save my decoded base64 into storage folder but I got this error message; even the permission storage and all subdirectories is 775 .

Intervention\Image\Exception\NotWritableException: Can't write image data to path

My code

$image = $request->image; 
            $image = str_replace('data:image/png;base64,', '', $image);
            $image = str_replace(' ', '+', $image);
            $imageName = str_random(32).'.'.'png';
          \Image::make(base64_decode($image))>save('avatar/'.$imageName);

Storage path: /storage/app/public/avatar

I see that you missed dash symbol before save method, it should be:

\Image::make(base64_decode($image))->save('avatar/'.$imageName);

Also, you can check if directory exists, if there is no such directory then create it:

if (!File::isDirectory($path)) {
    File::makeDirectory($path, 0775, true);
}

Don't forget to include File facade at the top:

use Illuminate\Support\Facades\File;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM