Home > Backend Development > PHP Tutorial > Introduction to php chmod() function

Introduction to php chmod() function

怪我咯
Release: 2023-03-13 12:48:01
Original
2876 people have browsed it

The

chmod function of php can change the access permissions of files and folders, but when used, a Warning message is displayed, as follows:

Warning: chmod() [function.chmod]: Operation not permitted in /export/myTest/chmodTest.php on line 5
Copy after login

The access permissions of all superior folders of the modified folder were changed to 777. The chmod function did not modify the access permissions of the folder at all. What is the reason? *nix just needs to make all the files in the web root directory owned by the apache running user. Assuming that there is an apache user in the apache group running httpd, then

chown -R apache.apache /path to DocumentRoot/

For win, the iis running user must have all permissions on DocumentRoot.


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

Syntax

chmod(file,mode)
Copy after login


##ParametersDescriptionfileRequired. 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

php chmod() function example

<?php
// 所有者可读写,其他人没有任何权限
chmod("test.txt",0600);

// 所有者可读写,其他人可读
chmod("test.txt",0644);

// 所有者有所有权限,其他所有人可读和执行
chmod("test.txt",0755);

// 所有者有所有权限,所有者所在的组可读
chmod("test.txt",0740);
?>
Copy after login


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

Related labels:
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