Skip to content

Instantly share code, notes, and snippets.

@gentritabazi
Last active September 12, 2024 13:09
Show Gist options
  • Save gentritabazi/5aadc42565a809d2f288da2bf7d806a2 to your computer and use it in GitHub Desktop.
Save gentritabazi/5aadc42565a809d2f288da2bf7d806a2 to your computer and use it in GitHub Desktop.
Copy all files from one folder to another folder using PHP script
<!-- https://stackoverflow.com/a/25780354/6055141 -->
function copyDirectory($source, $destination)
{
$directory = opendir($source);
@mkdir($destination);
while (false !== ($file = readdir($directory))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($source . '/' . $file)) {
copy_directory($source . '/' . $file, $destination . '/' . $file);
} else {
copy($source . '/' . $file, $destination . '/' . $file);
}
}
}
closedir($directory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment