7.3 Copying or Moving a File


You need to copy a file or move a file from one directory to another.

Technique

Use PHP's built-in copy() function:

 <?php if (copy ($original, $new)) {     print "$original copied to $new successfully"; } else {     print "alas, thine wish cannot be the computers command"; } ?> 

Or, if you need to move a file, use rename() :

 <?php rename($original, $new)   or die("Cannot Rename"); ?> 

Comments

The copy() function takes a source file and a destination file, and copies the source to the destination. If the destination file does not exist, PHP creates it. The rename() function makes a system call to the rename program.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net