0

I have a project I need to generate all sorts of PDF documents for with PHP, so I searched and found TCPDF. All seemd OK until I got to saving files to some folder.

So, I created the needed folder, set 0777 permissions to it, then proceded with generating a file into it. The file was created and all looks good, but the file now belongs to the 'daemon' user, and has 0644 permissions.

I need the generated files to have 0777 permissions. I dont' mind the 'daemon' user as owner, but it would be cool to also know how to set it to the 'root' user.

I searched the official documentation to TCPDF for an answer, but failed to find one, so I came here to ask for help.

So, can anyone help me with some sugestions?

1 Answers1

0

I have solved this problem in my Apache installations on Debian Server by setting the umask environment variable in /etc/apache/envvars.

In my case all I wanted was for the the user and group to have write permissions. I achieved this by setting the umask variable in that file to 007. The mask is applied to the permissions that are inherited by whatever user Apache is running under and so in my case the net result is that all files created by PHP within Apache have 660. I guess in your case you might need 000 (or 0000).

There is absolutely no point setting the execute permission and I would advise against it, because at best it achieves nothing and at worst it might introduce some strange security issue.

This answer contains more info on setting the umask: Setting the umask of the Apache user

The only benefit of this solution over PHP's chmod function is that you can "set it and forget it", the problem being that if you forget to set it then you have a problem.

Community
  • 1
  • 1
JamesG
  • 4,222
  • 2
  • 29
  • 36