PHPmkdir () has no write permission. When using mkdir to create a folder, we found that this function has two parameters. The second parameter is to specify permissions for the newly created folder. However, if mkdir (file address, 0777) is used directly, when mkdir is used to create a folder, this function has two parameters, and the second parameter is to specify permissions for the newly created folder.
However, if mkdir ('file address', 0777) is used directly, the permission of the new folder is not 777, which is generally.
Because when mkdir sets a permission for a folder, it matches the umask (default permission attribute) value of the user Currently logged on to the operating system. the obtained value is the final permission value.
What is umask?
What is the default permission for creating a file? How can I change the default permission?
When we log on to the system and create a file, there is always a default permission. how does this permission come from? This is what umask does.
Umask sets the default permission for the user to create files, which is the opposite of chmod. umask sets the permission "complement", while chmod sets the file permission code. Set umask in/etc/profile, $ HOME/. bash_profile, or $ HOME/. profile.
How to calculate the umask value?
The umask command allows you to set the default mode when creating a file. each type of user (file owner, users in the same group, and other users) has a number in the corresponding umask value. For files, the maximum value of this number is 6. The system does not allow you to grant the execution permission when creating a text file. you must use the chmod command to add this permission after the creation. Directory allows you to set the execution permission. for the directory, the maximum number of umask numbers is 7.
The command is generally in the form of umask nnn, where nnn can be 000-777.
We only need to remember that umask is "taking" the corresponding bit from the permission.
For example, if the umask value is 022, the default directory permission is 755, and the default file permission is 644.
Therefore, if the user umask is 022 (usually this is the default value), that is, 000 010 010 lies in the 777 specified by mkdir, that is, after 111 111 111 "and, the actual permission is: 022.
You can use either of the following methods to grant the maximum permission to a folder: (of course, the maximum permission is granted to the current user)
1. modify the user umask. php provides the umask function:
The code is as follows:
$ Oldumask = umask (0 );
Mkdir ('test', 0777 );
Umask ($ oldumask );
This method seems to be permanent. specify the umask value in the file starting with the script, and then directly use mkdir to control the permission. Note that when the umask function is used on a multithreaded server, multiple threads share one umask, which may cause confusion.
2. use the chmod function, which is also the most common method:
The code is as follows:
Mkdir ('file address', 0777 );
Chmod ('file address', 0777 );
Note that the permission value must start with "0" and must not be enclosed in quotation marks.
Bytes. If mkdir ('file address', 0777); is used directly...