Copying files with copy()
rename(), copy() also takes two parameters - the filename you wish to copy from, and the filename you wish to copy to. The difference between rename() and copy() is that calling rename() results in the file being in only one place, the destination, whereas copy() leaves the file in the source location as well as placing a new copy of the file into the destination.
$filename2 = $filename . '.old' ;
copy ( $filename , $filename2 ); ?>
The result of that script is that there will be a file
$filename and also a $filename.old, e.g. c:\\windows\\myfile.txt and c:\\windows\\myfile.txt.old.
Author's Note: this function will not copy empty (zero-length) files - to do that, you need to use the function
Next chapter: Deleting files with unlink() >>
Moving files with rename()
Files Reading files readfile() file_get_contents() and file() fopen() and fread() Creating and changing files file_put_contents() fwrite() Moving, copying, and deleting files Moving files with rename() Copying files with copy() Deleting files with unlink() Temporary files Other file functions Checking whether a file exists Retrieving a file's status Dissecting filename information A working example: making a counter Handling file uploads Advanced file upload handling Checking uploaded files Locking files with flock() Permissions Setting permissions Changing file ownership Working with directories Deleting directories One last directory function Remote files File checksums Parsing a configuration file Summary Exercises Further reading Next chapter
Table of Contents
Follow us on
Identi.ca or Twitter