Shell command to copy a directory to another location

In my web application, I need to copy the directory and all its contents to another location. I want to use a function shell_execfor PHP. But I can not find a team for this.

+5
source share
3 answers

You can use:

cp -r source dest

Copies the source and all contents of the source inside dest.

+7
source

Locate your location more accurately. Anyway:

  • if the local directory: cp -r sourcedir destdir;
  • if it is removed using scp: scp -r sourcedir user@targetmachine:destdir
+3
source

PHP copy function, directcotry. :

function recurse_copy($srcdir, $dstdir) {
    $dir = opendir($srcdir);
    @mkdir($dstdir);
    while ($file = readdir($dir)) {
        if ($file != '.'  && $file != '..') {
            $src = $srcdir . '/' . $file
            $ dst = $ dstdir. '/'. $ file
            if (is_dir ($ src)) { 
                recurse_copy ($ src, $ dst); 
            } else { 
                copy ($ src, $ dst); 
            }
        }
    }
    closedir ($ dir);
}
+2
source

All Articles