image icon indicating copy to clipboard operation
image copied to clipboard

Can't write image data to the path

Open knif3rdev opened this issue 8 years ago • 7 comments

I got that error. I'm trying to resize an image for my photo gallery. folder should have the album_id, please help me to fix this.

Intervention \ Image \ Exception \ NotWritableException Can't write image data to path Can't write image data to path (album_image/photos/16/1515270724.png)

Here's my code:

if($request->hasFile('photo')){ $photo = $request->file('photo'); $filenameToStore = time() . '.' . $photo->getClientOriginalExtension(); $location = $request->file('photo')->storeAs('album_image/photos/'.$request->input('album_id'), $filenameToStore); Image::make($photo)->resize(500,500)->save($location); }

knif3rdev avatar Jan 06 '18 20:01 knif3rdev

Are you sure the directory exists? If so does it have the right permissions? That's usually the isue

chris-faulkner avatar Jan 09 '18 20:01 chris-faulkner

an error Can't write image data to path (/var/www/html/laravel_project/public/uploads/profileImage/1532779085.jpg)

koushikSen avatar Jul 28 '18 11:07 koushikSen

Are you sure the directory exists? If so does it have the right permissions? That's usually the isue

I am also getting the same error. how do we have the right permission??

jaikangam avatar May 15 '19 13:05 jaikangam

I would double check the path you are trying to save to and ensure it exists. This most often happens if the folder doesn't exist, so you'll need to check and ensure it exists in your code before saving.

If it does exist then perhaps check permissions on the folder, this depends on your operating system etc so best to Google that.

chris-faulkner avatar May 15 '19 13:05 chris-faulkner

@chris-faulkner you are perfectly right because it throws an error if the folder doesn't exist.

willypelz avatar Jun 06 '20 08:06 willypelz

I think it's worth asking why the library doesn't auto-create the folder?

Stoyvo avatar Jun 25 '20 01:06 Stoyvo

I've recently come across this issue, and in my case was that I needed to use the absolute path of the folder in order for it to upload.

mburkeSencon avatar Sep 09 '22 13:09 mburkeSencon

how to solve this error

moynuddin-ablion avatar Mar 21 '23 13:03 moynuddin-ablion

I solved it like this $photo = 'uploads/'.time().'.'.$request->file('photo')->getClientOriginalExtension(); $path = storage_path('app/public/'.$photo); $imgFile = Image::make($request->file('photo')); $imgFile->fit(150,150)->save($path); I noticed the following:

  1. you have to specify the full folder path, hence i used storage_path('app/public/
  2. the folder where you want to save your image must exist
  3. The permission for that folder (maybe public or storage, whichever) must be set to writable.

dreigningking avatar Jun 16 '23 11:06 dreigningking

In my case I was trying to upload the image like this

public function cargarImagen(PostRequest $request)
    {
        $imagen = $request->file('imagen');

        $nombreImagen = Str::uuid() . "." . $imagen->extension();

        $imagenServidor = Image::make($imagen);
        $imagenServidor->fit(1000, 1000);

        $imagenPath = public_path('uploads') . '/' . $nombreImagen;
        
        $imagenServidor->save($imagenPath);

        return $nombreImagen;
    }

The uploads folder exists but still the problem remained, I applied @dreigningking solution about to specify the full folder path and it worked

$imagenPath = storage_path('app/public/uploads/' . $nombreImagen);

The first time my original code worked fine was when instead of uploading the image in a common form I uploaded the images using unpkg.com/dropzone I think that library do something that help to avoid this issue

Genebi avatar Jun 29 '23 05:06 Genebi