smagafu's avatar

error message when saving image

hey guys am trying to upload files and saving image to my disk, but i get this error message any help error code is

NotWritableException in Image.php line 138: Can't write image data to path (public/img/products/2015-06-08-16:37:54-product2-hover.jpg)

and my code is.


            $product = new Item;
            $product->titlename = $item->itemname;
            $product->designer = $item->designer;
            $product->brand = $item->brand;
            $product->available = $item->available;
            $product->size = $item->size;
            $product->description = $item->description;

            //check if images are upladed
            if($item->hasFile('frontimage')){
                $frontImage = $item->file('frontimage');
                $filename = date('Y-m-d-H:i:s')."-".$frontImage->getClientOriginalName();
                $img = Image::make($frontImage->getRealPath())->resize(468, 249)->save('public/img/products/'.$filename);
                $product->imageFront = 'img/products/'.$filename;
                $product->save();
0 likes
9 replies
davidfaux's avatar

Make sure the img/* folders are writable chmod -R 755 public/img

1 like
absiddiqueLive's avatar

@smagafu You have to provide Write permission in the directory public/img/products/. You may provide 777 if have no security issue else make owner www-data and give 755.

chown -R www-data public/img/products/
chmod -R 755 public/img/products/

OR

chown -R www-data public/img/
chmod -R 755 public/img/

as your needs !

1 like
smagafu's avatar

Thank you guys. but its not working. dfaux, absiddiqueLive

smagafu's avatar

Thank you guys. but its not working. dfaux, absiddiqueLive

davidfaux's avatar

I'm not sure if Image::make() is aware of where the root of the project is, perhaps update this to a more definitive value if only to rule this out:

$img = Image::make($frontImage
        ->getRealPath())
        ->resize(468, 249)
        ->save(public_path("img/products/{$filename}"));
MaverickChan's avatar

Image or other image processor does NOT know how to create folder. My solution is add a couple of php code lines before you save .

example :

......

if (!file_exists($thumbnail_path)) {
            mkdir($thumbnail_path, 0777, true);
        }

 Image::make($path.'/'.$filename)
                ->fit(400,225)
                ->save($thumbnail_path.'/'.$filename);

 Session::flash('message','Image Uploaded !');

Please or to participate in this conversation.