Let’s take a look at this php copy function tutorial.
copy
(PHP 4, PHP 5)
Copy - Copy file
Description
boolean copy(string$source, string$dest[, resource$background])
Makes a copy of the file dest.
If you want to move the file, please use the rename() function.
Parameters
Source
The path to the source file.
dest
Destination path. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting existing files.
Warning
If the target file already exists, it will be overwritten.
Background
Establish stream_context_create() within the valid scope of the resource.
Return value
Returns TRUE or FALSE on success or failure.
Modify
Release Notes
5.3.0 timing support.
4.3.0 source and dest may now be urled if "unpack" is enabled. See the fopen() function for more details.
Example
Example of #1copy()
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}
?>