What permissions are required to rename a file in PHP?

When renaming a file in PHP, the script must have the appropriate permissions to modify the file. This typically means that the script must have write permissions for the directory where the file is located. If the script does not have the necessary permissions, the file rename operation will fail.

// Check if the script has write permissions for the directory
if (is_writable(dirname($oldFilePath))) {
    // Rename the file
    if (rename($oldFilePath, $newFilePath)) {
        echo "File renamed successfully.";
    } else {
        echo "Error renaming file.";
    }
} else {
    echo "Script does not have write permissions for the directory.";
}