The copy() function copies a file.
PHP copy() Function has the following syntax.
copy(file,to_file)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to copy |
to_file | Required. | File to copy to |
If the destination file already exists, it will be overwritten.
This function returns TRUE on success and FALSE on failure.
Files are copied using copy().
<?php
echo copy("source.txt","target.txt");
?>
copy() takes two parameters: the filename you wish to copy from and the filename you wish to copy to.
<?PHP/*from w w w .jav a 2s. co m*/
$filename = "c:/abc/test.txt";
$filename2 = $filename . '.old';
$result = copy($filename, $filename2);
if ($result) {
print "$filename has been copied to $filename2.\n";
} else {
print "Error: couldn't copy $filename to $filename2!\n";
}
?>