Problem Description:
Use the following PHP code to create a directory that expects directory permissions to be 0777 and the actual result is 0755
mkdir ('./aa/', 0777);
Analysis and test results:
the directory permissions specified by the 1.mkdir () function can only be less than the default permissions set by the system umask.
such as Linux default Umask general 0022, that is, the default permission to create a directory is 0755, so php mkdir ('./aa/', 0777) access to the directory is 0755.
xw@xw-x201:~/desktop/dd/aa$ umask
0022
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw/', 0777);"
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw1/', 0755);"
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw2/', 0747);"
xw@xw-x201:~/desktop/dd/aa$ ll
total dosage
drwxrwxrwx 5 xw xw 4096./
11:58 6 drwxr-xr-x XW 4096 20 12-06-01 11:26. /
drwxr-xr-x 2 xw xw 4096 11:57 xw/
drwxr-xr-x 2 xw xw 4096 11:58 xw1/drwxr--r-x
2 x W XW 4096 11:58 xw2/
Change the system default permissions to 777,mkdir () to specify greater permissions
xw@xw-x201:~/desktop/dd/aa$ umask
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw2/', 0777);"
xw@xw-x201:~/desktop/dd/aa$ ll
total dosage of
drwxrwxrwx 3 XW xw 4096./
12:08 6 drwxr-xr-x XW 4096 2012 -06-01 11:26. /
drwxrwxrwx 2 XW xw 4096 12:08
The 2.chmod () function is not affected by the system Umask and can set permissions larger than the system default permissions.
xw@xw-x201:~/desktop/dd/aa$ umask
0022
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw1/', 0777);"
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw2/');"
xw@xw-x201:~/desktop/dd/aa$ php-r "mkdir ('./xw3/'); chmod ('./xw3/', 0777);"
xw@xw-x201:~/desktop/dd/aa$ ll
total dosage
drwxrwxrwx 5 xw xw 4096./
12:12 6 drwxr-xr-x XW 4096 2 012-06-01 11:26. /
drwxr-xr-x 2 xw xw 4096 12:11 xw1/
drwxr-xr-x 2 xw xw 4096 12:11 xw2/drwxrwxrwx
2 XW XW 4096 12:12 xw3/
3. The system's mkdir command can set permissions greater than the default value.
xw@xw-x201:~/desktop/dd/aa$ umask
0022
xw@xw-x201:~/desktop/dd/aa$ mkdir-m0777 XW
desktop/dd/aa$ ll
total dosage
drwxrwxrwx 3 xw xw 4096 12:18./
drwxr-xr-x 6 XW xw 4096 2012-06-01 11:26 .. /
drwxrwxrwx 2 XW xw 4096 12:18
Summarize:
PHP to create a directory with read and write permissions, it is best to use the following code, do not directly use the MkDir function to specify permissions to avoid the impact of system Umask
mkdir ('./xw/');
chmod ('./xw/', 0777);