Skip to content

Instantly share code, notes, and snippets.

@bryceleue
Forked from gserrano/recursive_copy_files.php
Last active January 28, 2020 04:02
Show Gist options
  • Save bryceleue/bb9325f61586eaca5c7c437eca8de957 to your computer and use it in GitHub Desktop.
Save bryceleue/bb9325f61586eaca5c7c437eca8de957 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) ) {
recursive_copy($src .'/'. $file, $dst .'/'. $file);
}
else {
copy($src .'/'. $file,$dst .'/'. $file);
}
}
}
closedir($dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment