Given a source and destination directory, the following function will copy contents between the two locations. Generally speaking, this isn't the code I use myself. I'll generally log into another remote server using PHP's FTP functions ... although the same principles apply.
To copy a single file, use PHP's copy() function. It's requires a path (or URL) to your source and path to a destination location. Because filenames are required, you may alter the name of the destination file.
PHP Function
This function will recursively copy all contents of a directory.
If you find that the source directory has a lot of content and is large in size (causing the copy to time out), you can use the following to potentially fix your problem. The value you set will be the script maximum execution time.
set_time_limit(0);
If you get an error message because your server is configured in safe-mode, try this rather than the above:
A value of '0' will set the execution timeout limit to 'infinity'.
Download
Title: Copy directory contents with PHP
Description: Copy the contents of a directory from one location to another with PHP.
Download • Version 0.2, 616.0B, zip, Category: PHP Code & Snippets