Why can't PHP create a directory with 777 permissions?
Answers
-
The mode is modified by your current
umask
, which is022
in this case.The way the
umask
works is a subtractive one. You take the initial permission given tomkdir
and subtract theumask
to get the actual permission:0777 - 0022 ====== 0755 = rwxr-xr-x.
If you don't want this to happen, you need to set your
umask
temporarily to zero so it has no effect. You can do this with the following snippet:$oldmask = umask(0); mkdir("test", 0777); umask($oldmask);
The first line changes the
umask
to zero while storing the previous one into$oldmask
. The second line makes the directory using the desired permissions and (now irrelevant)umask
. The third line restores theumask
to what it was originally.0
Howdy, Stranger!
Categories
- 94 All Categories
- 20 VoIP
- 7 SIP
- 16 asterisk
- 44 Programming
- 1 Nodejs
- 4 javascript
- 19 PHP
- 8 Codeigniter
- 14 database
- 1 UI/UX
- 2 Flutter
- 28 OS
- 26 Linux
- 1 Virtualization
- 1 Android
- 1 Windows
- 2 legal