Last active
August 29, 2015 14:20
-
-
Save igodorogea/90d1c48a96140d8dd747 to your computer and use it in GitHub Desktop.
PHP copy directory recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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