Problem Description:
Use the following PHP code to create a directory, the permissions of the expected directory is 0777, the actual result is 0755
Copy CodeThe code is as follows: mkdir ('./aa/', 0777);
Analysis and test results:
The 1.mkdir () function specifies that the directory permission can be less than or equal to 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) the permission to get the directory is 0755. The
copy Code code is as follows:
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 usage
drwxrwxrwx 5 xw xw 4096 2012-06-01 11:58./
Drwxr-xr-x 6 XW XW 4096 201 2-06-01 11:26.. /
Drwxr-xr-x 2 xw xw 4096 2012-06-01 11:57 xw/
drwxr-xr-x 2 xw xw 4096 2012-06-01 11:58 xw1/
Drwxr--r-x 2 XW XW 4 096 2012-06-01 11:58 xw2/
Change system default permissions to 777,mkdir () to specify greater permissions
copy code code as follows:
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 usage:
drwxrwxrwx 3 XW xw 4096 2012-06-01 12:08./
Drwxr-xr-x 6 XW XW 4096 201 2-06-01 11:26.. /
drwxrwxrwx 2 xw xw 4096 2012-06-01 12:08 xw2/
The
2.chmod () function is not affected by system umask and can be set to a greater extent than the system's default permissions. The
Copy Code code is as follows:
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 usage
drwxrwxrwx 5 xw xw 4096 2012-06-01 12:12./
Drwxr-xr-x 6 XW XW 4096 201 2-06-01 11:26.. /
Drwxr-xr-x 2 xw xw 4096 2012-06-01 12:11 xw1/
drwxr-xr-x 2 xw xw 4096 2012-06-01 12:11 xw2/
drwxrwxrwx 2 XW XW 4096 2012-06-01 12:12 xw3/
3. The system's mkdir command can set permissions greater than the default value.
Copy the Code code as follows:
xw@xw-x201:~/desktop/dd/aa$ Umask
0022
xw@xw-x201:~/desktop/dd/aa$ mkdir-m0777 XW
xw@xw-x201:~/desktop/dd/aa$ LL
Total Dosage 12
DRWXRWXRWX 3 XW xw 4096 2012-06-01 12:18./
Drwxr-xr-x 6 XW xw 4096 2012-06-01 11:26.. /
DRWXRWXRWX 2 XW xw 4096 2012-06-01 12:18 xw/
Summarize:
PHP to create a directory with read and write permissions, it is best to use the following code, do not use the MkDir function directly to specify permissions to avoid the effects of system umask
Copy the Code code as follows:
mkdir ('./xw/');
chmod ('./xw/', 0777);