The chmod () function changes the file mode.Chmod-Changes file mode
TRUE is returned if the call succeeds. Otherwise, FALSE is returned.
Syntax
Chmod (file, mode)
Parameters |
Description |
File |
Required. Specifies the file to be checked. |
Mode |
Optional. Specify new permissions. The mode parameter consists of four numbers:
- The first digit is always 0.
- The second number specifies the owner's permissions.
- The second number specifies the permissions of the user group to which the owner belongs.
- The fourth digit specifies the permissions of the other owner.
Possible values (if you need to set multiple permissions, Please sum up the following numbers ):
- 1-execution permission
- 2-write permission
- 4-read permission
|
Let's look at a simple example.
<? Php Tutorial
Chmod ("/somedir/somefile", 755); // decimal; probably incorrect
Chmod ("/somedir/somefile", "u + rwx, go + rx"); // string; incorrect
Chmod ("/somedir/somefile", 0755); // octal; correct value of mode
?>
Improved recursive file mode @ infosoft... this is a small short file type that should be processed by all Linux file systems. This allows you to change the permissions of files or directories in batches.
<? Php
Function chmodr ($ path, $ filemode ){
If (! Is_dir ($ path ))
Return chmod ($ path, $ filemode );
$ Dh = opendir ($ path );
While ($ file = readdir ($ dh ))! = False ){
If ($ file! = '.' & $ File! = '..'){
$ Fullpath = $ path. '/'. $ file;
If (is_link ($ fullpath ))
Return FALSE;
Elseif (! Is_dir ($ fullpath )&&! Chmod ($ fullpath, $ filemode ))
Return FALSE;
Elseif (!Chmodr ($ Fullpath, $ filemode ))
Return FALSE;
}
}
Closedir ($ dh );
If (chmod ($ path, $ filemode ))
Return TRUE;
Else
Return FALSE;
}
?>
If you have too many directories, you can use
<? Php
$ Iterator = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ pathname), RecursiveIteratorIterator: SELF_FIRST );
Foreach ($ iterator as $ item ){
Chmod ($ item, $ filemode );
}
?>
This code is used to modify the directory permissions.
Haha, we are not only talking about the simple chmod syntax, but also doing complicatedChmodUse instance