How to set default permissions for new files created using php

Hi, I am running a centos server and I want to know how I can set chmod by default for a newly created file that php creates, like fopen. At the moment it makes 644, but I want 666, and where can I specify this parameter?
+4
source share
2 answers

Like Linux, PHP has a chmod () command that can be called to change file permissions.

See the documentation here: http://php.net/manual/en/function.chmod.php

For the default setting, you can try Patrick Fisher here: Installing umask for the Apache user

[root ~]$ echo "umask 000" >> /etc/sysconfig/httpd [root ~]$ service httpd restart 
+2
source

You can use umask() just before calling fopen (), but umask should not be used if you are on a multi-threaded server - it will change the mask for all threads (for example, this change is at the process level), and not just the one you going to use fopen ().

eg.

 $old = umask(000); fopen('foo.txt', 'w'); // creates a 0666 file umask($old) // restore original mask 

It would be easier to just chmod () after the fact, however:

 fopen('foo.txt', 'w'); // create a mode 'who cares?' file chmod('foo.txt', 0666); // set it to 0666 
+5
source

Source: https://habr.com/ru/post/1481971/


All Articles