chmod() function changes the file mode. chmod — Changes file mode Returns TRUE if successful, FALSE otherwise.
Syntax
chmod(file,mode) Parameter Description
file Required. Specifies the documents to be checked.
mode Optional. Specify new permissions.
The mode parameter consists of 4 numbers:
The first number is always 0
The second number specifies the permissions of the owner
The second number specifies the permissions of the user group to which the owner belongs
The fourth number specifies the permissions of everyone else
Possible values (to set multiple permissions, please total the numbers below):
1 - Execute permissions
2 - Write permissions
4 - Read permissions
Let’s see a simple example
Improved recursive file mode@infosoft...., This is a small shortcut that should handle all file types of the Linux file system. This can change the permissions of files or directories in batches
If you have too many directories, you can use
This code to modify the permissions of the directory
Haha, we are not just talking about simple chmod syntax, and also made complex examples of chmod usage
Explanation
bool chmod (string $filename, int $mode)
Try to change the mode of the file specified by filename to that given by mode.
Note that mode will not be automatically treated as an octal value, and strings (such as "g+w") cannot be used. To ensure correct operation, you need to add 0 in front of mode:
The mode parameter contains three octal numbers that 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. For information about file permissions on UNIX systems, read the manuals "man 1 chmod" and "man 2 chmod".
Returns TRUE if successful and FALSE if failed.
Note: The current user refers to the user executing PHP. Most likely not the same as the usual shell or FTP user. On most systems a file's mode can only be changed by the user who owns the file.
Note: This function cannot be used on remote files. The files being checked must be accessed through the server's file system.
Note: When safe mode is turned on, PHP will check whether the file being operated on has the same UID (owner) as the script being executed. It should be noted that SUID, SGID and sticky bits cannot be modified.
The above is the detailed content of Detailed explanation of PHP's file permission function chmod. For more information, please follow other related articles on the PHP Chinese website!