What are the implications of using copy() function in PHP for file manipulation tasks?

When using the copy() function in PHP for file manipulation tasks, it's important to consider potential errors that may occur, such as file permission issues or overwriting existing files unintentionally. To avoid these problems, you can check if the file exists before copying it and handle any errors that may arise during the process.

$sourceFile = 'source.txt';
$destinationFile = 'destination.txt';

if (file_exists($sourceFile)) {
    if (!copy($sourceFile, $destinationFile)) {
        echo "Error copying file";
    } else {
        echo "File copied successfully";
    }
} else {
    echo "Source file does not exist";
}