0

When trying to save an image on my server, in my laravel 5 project with intervention image class, with the following code :

$pathFull = public_path('images/original/brand/' . $filename);
$img = Image::make($image->getRealPath());
$img->encode('jpg')->save($pathFull);

I get the error:

NotWritableException in Image.php line 138:
Can't write image data to path  
(/var/www/mydomain.com/public/images/original/brand/nanan.jpg)

So ive changed permission on the folder (that already exists) with:

sudo chmod -R 775 /var/www/mydomain.com/public/images

Ive checked the permissions they are 775 so that command works. I tried it localy (xampp) and it worked fine and the driectory paths are fine. I keep getting this error only if i use 777 i don't but thats danerous.

What else can I try to keep the server save and not use 777?

Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169
  • @maytham the pictures dont need to be protected why should i use routes for the images than? – Sven van den Boogaart Jul 16 '15 at 01:14
  • @mayham but than i need to create unnecesary routes using 775 on public should be perfectly safe. – Sven van den Boogaart Jul 16 '15 at 01:25
  • If you think that is the way to go, that's fine dude, was just a suggestion. – Maytham Fahmi Jul 16 '15 at 01:27
  • @maytham thanks for the suggestion i might use it but it doesnt explain why I cant write at the moment. and i really like to find out what i did wrong so i can avoid it in the future – Sven van den Boogaart Jul 16 '15 at 01:28
  • have you solved this issue yet? I have check your code and it should works fine if your public folder is welling to have write permission as your problem occur, so I do not suspect your code, I do only suspect some thing with write permission in your system/folder structure. – Maytham Fahmi Jul 25 '15 at 00:36

1 Answers1

0

Maybe the paths are not the same. Check it out. See the original directory?

$pathFull = public_path('images/brand/thumb/' . $filename);

Can't write image data to path  
(/var/www/mydomain.com/public/images/original/brand/nanan.jpg)

sudo chmod -R 775 /var/www/mydomain.com/public/images/original/brand

I have made recently a method like yours. It works fine for me. Here it is:

$image = Input::file('image');
$filename = Input::file('image')->getClientOriginalName();
$path = public_path('images/' . Auth::user()->email . '/' . $filename);
$img = Image::make($image->getRealPath());
$img->encode('jpg')->save($path);
therealbigpepe
  • 1,489
  • 2
  • 16
  • 23