PHP Developers Cookbook (2nd Edition)

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.

Категории