chmod()
chmod() — Changes file mode.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Attempts to change the mode of the specified file to that given in permissions.
Signature
chmod(string $filename, int $permissions): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $filename | string | Path to the file. |
| $permissions | int | Note that permissions is not automatically assumed to be an octal value, so to ensure the expected operation, you need to prefix permissions with a zero (0). Strings such as "g+w" will not work properly. |
Return value
Returns true on success or false on failure.
Example
The PHP manual ships no example for chmod(); the signature and the parameter table above are the contract.
See also
chown(), chgrp(), fileperms(), stat()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page chmod() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.