What is the function 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/source/file.txt';
$destinationFile = 'path/to/destination/file.txt';

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