The mkdir () function of php creates a folder with a safer permission setting method ,. The mkdir () function of php creates a safe permission setting method for folders. problem description: a directory is created using the following php code, and the expected Directory permission is 0777, the actual result is that the mkdir () function of 0755 php is used to create a secure permission setting method for folders,
Problem description:
Use the following php code to create a directory. the expected permission for the directory is 0777, and the actual result is 0755.
The code is as follows:
Mkdir ('./aa/', 0777 );
Analysis and test results:
1. the directory permission specified by the mkdir () function must be less than or equal to the default permission set by the system umask.
For example, the default umask in linux is generally 0022, that is, the default permission for creating a directory is 0755. Therefore, the directory permission obtained by php mkdir ('./aa/', 0777) is 0755.
The 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 20
Drwxrwxrwx 5 xw 4096 ./
Drwxr-xr-x 6 xw 4096 ../
Drwxr-xr-x 2 xw 4096 xw/
Drwxr-xr-x 2 xw 4096 xw1/
Drwxr -- r-x 2 xw 4096 xw2/
Change the default system permission to 777, and mkdir () can specify more permissions.
The code is as follows:
Xw @ xw-X201 :~ /Desktop/dd/aa $ umask 000
Xw @ xw-X201 :~ /Desktop/dd/aa $ php-r "mkdir ('./xw2/", 0777 );"
Xw @ xw-X201 :~ /Desktop/dd/aa $ ll
Total usage 12
Drwxrwxrwx 3 xw 4096 ./
Drwxr-xr-x 6 xw 4096 ../
Drwxrwxrwx 2 xw 4096 xw2/
2. the chmod () function is not affected by the system umask. you can set a higher permission than the default permission of the system.
The 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 20
Drwxrwxrwx 5 xw 4096 ./
Drwxr-xr-x 6 xw 4096 ../
Drwxr-xr-x 2 xw 4096 xw1/
Drwxr-xr-x 2 xw 4096 xw2/
Drwxrwxrwx 2 xw 4096 xw3/
3. the mkdir command of the system can be used to set permissions greater than the default value.
The code is 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 usage 12
Drwxrwxrwx 3 xw 4096 ./
Drwxr-xr-x 6 xw 4096 ../
Drwxrwxrwx 2 xw 4096 xw/
Summary:
To create a directory with read and write permissions for php, you 'd better use the following code. do not directly use the mkdir function to specify permissions to avoid the impact of the umask system.
The code is as follows:
Mkdir ('./xw /');
Chmod ('./xw/', 0777 );
The authorization () function creates a safe permission setting method for folders. problem description: a directory is created using the following php code. the expected permission for the directory is 0777. the actual result is 0755...