Home >Backend Development >PHP Problem >php modify file permissions
php modify file permissions
To modify file permissions in php, you can modify the permissions by using the "chmod()" function in php
chmod description and syntax
chmod will try to change the mode of the file specified by filename to that given by mode.
chmod ( string $filename , int $mode ) : bool
chmod parameters
filename: The path of the file.
mode:
Note that mode will not be automatically treated as an octal value, and it cannot use a string (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 // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner's group chmod("/somedir/somefile", 0750); ?>
chmod return value
Returns TRUE on success, or FALSE on failure.
The above is the detailed content of php modify file permissions. For more information, please follow other related articles on the PHP Chinese website!