Skip to content

Instantly share code, notes, and snippets.

@igodorogea
Last active August 29, 2015 14:20
Show Gist options
  • Save igodorogea/90d1c48a96140d8dd747 to your computer and use it in GitHub Desktop.
Save igodorogea/90d1c48a96140d8dd747 to your computer and use it in GitHub Desktop.
PHP copy directory recursive
<?php
function copy_directory($src, $dst) {
if (file_exists($src)) {
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {
if (file_exists($dst . '/' . $file)) {
unlink($dst . '/' . $file);
}
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