Can't write image data to the path
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); }
Are you sure the directory exists? If so does it have the right permissions? That's usually the isue
an error Can't write image data to path (/var/www/html/laravel_project/public/uploads/profileImage/1532779085.jpg)
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??
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 you are perfectly right because it throws an error if the folder doesn't exist.
I think it's worth asking why the library doesn't auto-create the folder?
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.
how to solve this error
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:
- you have to specify the full folder path, hence i used
storage_path('app/public/ - the folder where you want to save your image must exist
- The permission for that folder (maybe public or storage, whichever) must be set to writable.
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