简体   繁体   中英

Laravel “Can't write image data to path” error

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.

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 eg :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM