Home  >  Article  >  Backend Development  >  Instructions for using php chmod() function

Instructions for using php chmod() function

怪我咯
怪我咯Original
2017-07-11 09:20:401846browse

chmod() FunctionChange the file mode. Return TRUE if successful, otherwise return FALSE.

Syntax

chmod(file,mode)
Parameters Description
file Required. Specifies the documents to be checked.
mode

Optional. Specify new permissions.

mode parameter consists of 4 numbers:

  • The first number is always 0

  • The second number is specified The owner's permissions

  • The second number specifies the permissions of the user group to which the owner belongs

  • The fourth number specifies the permissions of everyone else Permissions

Possible values ​​(to set multiple permissions, total the numbers below):

  • 1 - Execute permissions

  • 2 - Write permission

  • 4 - Read permission

Note that mode will not be automatically regarded as an octal value, and strings (such as "g+w") cannot be used. To ensure correct operation, mode needs to be preceded by 0:

<?php
chmod ("/somedir/somefile", 755);   // 十进制数,可能不对
chmod ("/somedir/somefile", "u+rwx,go+rx"); // 字符串,不对
chmod ("/somedir/somefile", 0755);  // 八进制数,正确的 mode 值
?>

mode The parameter contains three octals The numbers specify the owner, the owner's group, and everyone's access restrictions in order. Each part can be calculated by adding the required permissions. The number 1 makes the file executable, the number 2 makes the file writable, and the number 4 makes the file readable. Add these numbers to specify the required permissions.

The above is the detailed content of Instructions for using php chmod() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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