Reputation:
I am currently using the Intervention Image package within Laravel.
I am wanting a user to have the ability to upload a logo. So far, I have the following:
public function postUpdateLogo($id) {
if(Input::file())
{
$image = Input::file('logo');
$filename = time() . '.' . $image->getClientOriginalExtension();
\Image::make($image->getRealPath())
->resize(300, 300)
->save('user/'. $id . '/' . $filename);
$user->image = $filename;
$user->save();
}
}
But the error I'm getting upon submission is:
NotWritableException in Image.php line 143: Can't write image data to path (user/1/1439491280.png)
Any help would be hugely appreciated.
Upvotes: 2
Views: 6166
Reputation: 2785
I came across this problem too, as Stuard suggested you might want to write in the public folder.
$filename = time() . '.' . $image->getClientOriginalExtension();
$path = public_path("user/".$id."/".$filename);
\Image::make($image->getRealPath())->resize(300, 300)->save($path);
Secondly I managed to fix my problem (ubuntu, apache, laravel 5 setup) by making apache the owner of that public folder e.g. :
sudo chown -R www-data:www-data /home/youruser/www/dev.site.com/public/user
add the right folder permission:
~$ sudo chmod 755 -R user
Might not be a perfect solution but will get you going.
Edit - a possible second option:
Checking the current group owner of your public folder and then adding apache user (www-data) to that group might be a second option (hope the gurus agree):
sudo adduser www-data theownergroup
Upvotes: 1