chmod

bool chmod(string file, int mode) 

Changes the access permissions of a file.

Returns:

TRUE on success; FALSE on error

Description:

chmod() changes the permissions of the specified file. The file mode should be specified in octal format and hence should have a leading 0. For more information on octal notation of file permissions, see the UNIX man page on chmod.

Note:

If safe mode is enabled, chmod() can only change the permissions of files that are owned by the user running the command. In most cases, this is the user that the web server runs as.

Example:

Change a file’s permissions to “-rw-r--r--”
$file = "test_file"; 

if (! chmod($file, 0644)) {
    echo ("Unable to change file permissions"); 
} 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.