Detailed explanation of PHP built-in function mkdir()_PHP tutorial

WBOY
Release: 2016-07-13 17:40:59
Original
1005 people have browsed it

The function mkdir has two parameters, directory path and access permissions
Example mkdir(/tmp/test,0777)

Then the permission code to be obtained is not necessarily the one set above. The umask of the current system will be 'AND'd with the set value. This is the real permission code. For example, if the umask is 022, the permission code obtained above is 0755, and there is no writing permission
So if we want to really get the permission of 0777, the code
$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?
How do we get the default permissions for creating files? How to change this default permission?
When we log in to the system and create a file, there is always a default permission. So where does this permission come from? This is what umask does. umask sets the default permissions for files created by users. It has the opposite effect of chmod. umask sets the permission "complement code", while chmod sets the file permission code. Generally, the umask value is set 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 files, corresponding to each type of user (file owner, users in the same group, other users ) exists a corresponding number in the umask value. For files, the maximum value of this number is 6. The system does not allow you to give execution permission to a text file when you create it. You must use the chmod command to increase this permission after creation. Directories allow setting execution permissions, so for directories, the maximum number in umask can be up to 7.

The general form of this command is: umask nnn, where nnn can be 000 - 777.

We just need to remember that umask "takes away" the corresponding bit from the permissions.

For example: if the umask value is 022, the default directory permission is 755 and the default file permission is 644.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486179.htmlTechArticleThe function mkdir has two parameters, directory path and access permissions. For example, mkdir(/tmp/test,0777) and then The obtained permission code is not necessarily the one set above. The current system umask will be the same as the set value...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!