Can't write image data to path - Intervention Image

I'd been wracking my brain for a few days about this, searching the web for a solution to "Can't write image data to path (storage/thumbs/filename.jpeg)". Then it finally hit me, it was a permissions issue.

I needed to give the webserver (Apache in my case) ownership of the folder i was wanting to save files to. My current setup is to share the ownership of the files / folders with myself and the webserver.

You can see my post about how to set file permissions for Laravel 5 on mac OSX, for more details.

As you can see from the screenshot below, within my storage/app/public folder i have a thumbnails folder which i wanted to save images to.

File permissions of the laravel storage folder

My user and _www share ownership of the folder. All i needed to do was change the ownership to be Apache for both. To do this type the following command in your terminal window:

cd yourprojectname/storage/app/public
sudo chown _www:_www thumbnails

The only side effect of this is that if you ever need to delete the files from the folder, you'll have to type your password in to authorise it, since you are no longer the owner of the files. However in a production environment it will be very likely that the webserver is the owner of all the files and folders in your project, so you'll never come across this problem, only when developing locally.

As a side note, You can use this fix for any project you use Intervention Image with. It's not Laravel dependant.

Hope this helps someone!

 


More Posts

Laravel PDF API

As part of my day job I was required to make PDF's from HTML templates and expose this via an...