What is the best way to copy a file and rename the copy using PHP?

To copy a file and rename the copy using PHP, you can use the `copy()` function to make a duplicate of the file and then use the `rename()` function to rename the copied file to the desired name.

$fileToCopy = 'originalFile.txt';
$newFileName = 'copiedFile.txt';

if (copy($fileToCopy, $newFileName)) {
    echo "File copied successfully.";
    
    if (rename($newFileName, 'newName.txt')) {
        echo "File renamed successfully.";
    } else {
        echo "Error renaming file.";
    }
} else {
    echo "Error copying file.";
}