Setting umask to 0000 (or just 0 ) means that previously created files or directories created will not have any rights that were originally revoked. In other words, a umask zero will cause all files to be created as 0666 or writable in the world. Directories created in umask 0 will be 0777 .
Usually, when you see umask(0) , it should follow the chmod() call directly to explicitly set the permissions needed for the newly created file or directory for something other than being written to the world.
Use caution when setting umask to zero! This can be dangerous and basically useful only for creating files that later need to be written by the web server when the web server is running as another user, who is a βrealβ user who will also need to be able to modify files created by the web server . Otherwise, the default system umask is likely to be 0022 , writable by the file owner, but not by others. In this case, if you are logged in under a normal user account, the file created by the web server under PHP will not be available to you.
Instead of creating files that are written to the world, it is usually better to manage directories that the web server writes more explicitly. If files created inside a directory must have certain group permissions, it may be advisable to set the sgid bit in the directory so that new files inside it inherit group ownership. Users who need access to the file must be members of the group that has access to it. This is much safer than creating read-only files written to the world.
php > umask(0); // Should get created as 666 php > touch('file1.txt'); // "2" perms revoked from group, others, gets created as 644 php > umask(022); php > touch('file2.txt'); // All revoked (2,4) from group, others, gets created as 600 php > umask(066); php > touch('file3.txt'); -rw-rw-rw- 1 me group 0 Aug 24 15:34 file1.txt -rw-r--r-- 1 me group 0 Aug 24 15:35 file2.txt -rw------- 1 me group 0 Aug 24 15:37 file3.txt
Michael Berkowski Aug 24 2018-12-12T00: 00Z
source share