Forum Moderators: coopster

Message Too Old, No Replies

how do I copy files from one dir to another?

         

michlcamp

5:06 am on Aug 20, 2005 (gmt 0)

10+ Year Member



I've created a small php script to create a new directory on the server, and now want to copy five files from one directory (on the same server) to the new directory.

Can anyone give me a good example for doing this? So far all I've found is:


$source_file = '/tmp/file.html';
$dest_file = '/home/mydomain/file.html';
copy($source_file, $dest_file);

thanks in advance

dreamcatcher

6:29 am on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

The copy function, like the move_uploaded_file function is for file uploading and moving a temporary file to its destination.

For moving the files, you need the rename() function:
[uk.php.net...]

$file = '/images/file.jpg';

rename($file, 'images/files/file.jpg');

This will move the file.jpg from the root images directory into the 'files' directory.

Hope that helps.

dc