2

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.

9
  • It sounds like the directory you're trying to save to isn't writable (777). Commented Aug 13, 2015 at 18:51
  • It also looks like you'll probably want to add some more info to the path, e.g. '/path/to/images/user/'.$id. ... Commented Aug 13, 2015 at 19:03
  • @JoelHinz, the user/$id/randomString would suffice I think? I don't think that's causing the problem though. Commented Aug 13, 2015 at 19:19
  • Well, yes, if you're trying to upload it to Laravel's root folder. Don't you want to put it in the public folder at least? Commented Aug 13, 2015 at 19:22
  • I thought that would default into the public directory? My intention was to put it in there though! Commented Aug 13, 2015 at 19:26

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.