What is the correct way to change file permissions using chmod in PHP?

When changing file permissions using chmod in PHP, it is important to specify the file path and the desired permissions in numeric format. The permissions should be represented as an octal number (e.g., 0644 for read and write permissions for the owner and read permissions for others). It is also important to handle any errors that may occur during the permission change process.

$file_path = 'path/to/file.txt';
$permissions = 0644;

if (chmod($file_path, $permissions)) {
    echo 'File permissions changed successfully.';
} else {
    echo 'Error changing file permissions.';
}