In PHP, you can use the built-in function chmod() to modify the permissions of the file; this function can change the permissions of the specified file. The syntax format is "chmod(file,mode)". If the modification is successful, it returns TRUE. , and returns FALSE if it fails.
Recommended: "PHP Video Tutorial"
PHP chmod() function can change the permissions of the specified file; if Returns TRUE on success and FALSE on failure.
chmod will try to change the mode of the file specified by file to that given by mode.
chmod(file,mode)
Parameters:
Note: mode will not be automatically treated as an octal value, and it cannot use strings (such as " g w"). To ensure correct operation, you need to add 0 in front of the mode:
<?php chmod("/somedir/somefile", 755); // 十进制数,可能不对 chmod("/somedir/somefile", "u+rwx,go+rx"); // 字符串,不对 chmod("/somedir/somefile", 0755); // 八进制数,正确的 mode 值 ?>
The mode parameter contains three octal numbers in order to specify the owner, the owner's group, and everyone's access restrictions. 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. For information about file permissions on UNIX systems, read the manuals "man 1 chmod" and "man 2 chmod".
<?php // 所有者可读写,其他人没有任何权限 chmod("test.txt",0600); // 所有者可读写,其他人可读 chmod("test.txt",0644); // 所有者有所有权限,其他所有人可读和执行 chmod("test.txt",0755); // 所有者有所有权限,所有者所在的组可读 chmod("test.txt",0740); ?>
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of How to modify file permissions in php?. For more information, please follow other related articles on the PHP Chinese website!