What is the purpose of the copy() function in PHP and how does it work?

The copy() function in PHP is used to copy a file from one location to another. It takes two parameters: the source file path and the destination file path. This function can be useful when you need to duplicate a file or move it to a different directory.

$sourceFile = '/path/to/sourceFile.txt';
$destinationFile = '/path/to/destinationFile.txt';

if (copy($sourceFile, $destinationFile)) {
    echo "File copied successfully!";
} else {
    echo "Error copying file.";
}