How can absolute server paths be beneficial when using the rename function in PHP?

When using the rename function in PHP to move or rename files, providing absolute server paths can be beneficial as it ensures the script will correctly locate the files regardless of the current working directory. This helps avoid potential errors or issues related to relative paths.

$oldFilePath = '/var/www/html/uploads/file.txt';
$newFilePath = '/var/www/html/uploads/newfile.txt';

if (rename($oldFilePath, $newFilePath)) {
    echo 'File moved successfully.';
} else {
    echo 'Error moving file.';
}