The chmod() function changes permissions of the specified file.
PHP chmod() Function has the following syntax.
chmod(file,mode)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
mode | Required. | New permissions. |
The mode parameter consists of four numbers:
Possible values (to set multiple permissions, add up the following numbers):
Returns TRUE on success and FALSE on failure.
<?PHP/* w w w . ja va2s . co m*/
//sets the file to readable, writable, and executable by all users
chmod("/var/www/myfile.txt", 0777);
//sets the file to readable, writable, and executable by owner,
//and just readable and writable by everyone else.
chmod("/var/www/myfile.txt", 0755);
// Read and write for owner, nothing for everybody else
chmod("test.txt",0600);
// Read and write for owner, read for everybody else
chmod("test.txt",0644);
// Everything for owner, read for owner's group
chmod("test.txt",0740);
?>