PHPmkdir () has no write permission. Solution

Source: Internet
Author: User
This article mainly introduces how to solve the problem of PHPmkdir () having no write permission. It gives a detailed explanation of umask and how to solve the problem of mkdir () having no write permission. If you need a friend, refer to the following:

This article mainly introduces how to solve the problem of PHP mkdir () having no write permission. It gives a detailed explanation of umask and how to solve the problem of mkdir () having no write permission. For more information, see

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, 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.

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.