The chmod Function
The chmod
function changes the permissions for the specified file.
It accepts the file path as the first parameter and the numeric value of permissions as the second parameter.
Returns true on success and false on error.
Syntax
chmod(string $filename, int $mode): bool
Example
Set permissions 0644
for the file 'example.txt'
:
<?php
$res = chmod('example.txt', 0644);
var_dump($res);
?>
Code execution result:
true
Example
Let's try to change permissions for a non-existent file:
<?php
$res = chmod('nonexistent.txt', 0644);
var_dump($res);
?>
Code execution result:
false
Example
Set permissions 0755 for a directory:
<?php
$res = chmod('mydir', 0755);
var_dump($res);
?>
Code execution result:
true