permission denied on GD2 file_put_contents

December 7, 2015 883 views
PHP Apache Ubuntu

Hi - I am attempting to write dynamically generated files to my server using GD2 within codeigniter's PHP framework. I've checked the file permissions on the directory and they don't seem to be a problem (755).

Here is the error

Message:  file_put_contents(img/uploads/img80.png): failed to open stream: Permission denied

and here is the code that attempts to write the file

 file_put_contents($imagePath, base64_decode($image[1]));

any idea of what might be causing the permission denied error?

1 comment
  • What permissions do you have on img/uploads in the directory where your script is located? What user account owns it? If you are running this within a web server like apache but you created or uploaded these folders as root, the web server process would not be able to write to them by default.

Be the first one to answer this question.