PHP built-in function mkdir ()

Source: Internet
Author: User

The mkdir function has two parameters: directory path and access permission.
For example, mkdir (/tmp/test, 0777)

The permission code to be obtained is not necessarily set above. The umask of the current system will be associated with the set value 'and'. This is the real permission Code, for example, if umask is set to 022, the authorization code obtained above the code is 0755, and there is no write permission.
So if we want to really get 0777 permissions, the code
<? PHP
$ Oldumask = umask (0 );
Mkdir (test, 0777 );
Umask ($ oldumask );
?>

Umask () checks and modifies the current umask code, and returns the current umask code
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.