Skip to content

Instantly share code, notes, and snippets.

@gserrano
Created November 19, 2015 22:14
Show Gist options
  • Save gserrano/4c9648ec9eb293b9377b to your computer and use it in GitHub Desktop.
Save gserrano/4c9648ec9eb293b9377b to your computer and use it in GitHub Desktop.
PHP Recursive copy files
/*
* This function copy $source directory and all files
* and sub directories to $destination folder
*/
function recursive_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->recursive_copy($src .'/'. $file, $dst .'/'. $file);
}
else {
copy($src .'/'. $file,$dst .'/'. $file);
}
}
}
closedir($dir);
}
@jlaso
Copy link

jlaso commented Oct 17, 2019

Hey, thanks for the function.
There is a little typo in the body
$this->recursive_copy should be just recursive_copy
Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment