What are the potential pitfalls of using absolute paths versus relative paths when working with the `rename()` function in PHP?
Using absolute paths in the `rename()` function can lead to issues when moving files between different directories or servers, as the absolute path may not be valid in all contexts. It is recommended to use relative paths instead, as they are more portable and flexible. To ensure that the paths are always correct, you can use the `__DIR__` magic constant to generate the absolute path dynamically based on the current directory.
$oldFilePath = __DIR__ . '/oldfile.txt';
$newFilePath = __DIR__ . '/newfile.txt';
if (rename($oldFilePath, $newFilePath)) {
echo "File moved successfully.";
} else {
echo "Error moving file.";
}