0

The purpose of this question can be served by writing independent function for each source & destination directory in an include file but I'm looking for a better approach.

The following function copy files from one source directory to one destination directory. How can I use this function to copy file from another source directory to destination directory?

Is array(); applicable here or explode(); shall be the right choice or none of these is applicable in this case?

if (isset($_POST['submit'])) {
$old_umask = umask(0);
if (!is_dir($dst)) mkdir($dst, 0777);
umask($old_umask);

function recurse_copy($src,$dst) { 
    $dir = opendir($src);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            }
            else {
                copy($src . '/' . $file,$dst . '/' . $file);
            }
        }
    }
    closedir($dir);
    //echo "$src";
}

$dir = $_POST['name']; 
$src = "/home/user/public_html/directory/subdirectory/source/"; 
$dst = "/home/user/public_html/directory/subdirectory/destination/$dir/"; 
recurse_copy($src,$dst);
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Asked many times before. Just search for `php recursive copy` on the top bar. One of the many duplicates: http://stackoverflow.com/questions/5707806/recursive-copy-of-directory – Aziz Saleh Jun 01 '14 at 18:56
  • that's not it. want to copy files from two different source directories to two two different destination directories. – Silent Galaxy Jun 01 '14 at 19:32

0 Answers0