Copying files with copy()

Like 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.

= $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 touch().


Next chapter: Deleting files with unlink() >>

Previous chapter: Moving files with rename()

Jump to:


Home: Table of Contents

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar