Created
September 28, 2015 21:24
-
-
Save cdsalmons/5c037a87c4c640c6ea15 to your computer and use it in GitHub Desktop.
PHP: Recursively copy a directory, including symlink support
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 | |
// Based on | |
// http://uk1.php.net/manual/en/function.copy.php#104020 | |
function copy_dir($src, $dst) | |
{ | |
if (is_link($src)) { | |
symlink(readlink($src), $dst); | |
} elseif (is_dir($src)) { | |
mkdir($dst); | |
foreach (scandir($src) as $file) { | |
if ($file != '.' && $file != '..') { | |
copy_dir("$src/$file", "$dst/$file"); | |
} | |
} | |
} elseif (is_file($src)) { | |
copy($src, $dst); | |
} else { | |
echo "WARNING: Cannot copy $src (unknown file type)\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment