Created
November 29, 2017 06:23
-
-
Save GerBawn/e8fda56f5bacd14b819af34ba24f76e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function copyDir($src, $dst) | |
{ | |
if (!is_dir($src)) { | |
throw new Exception('src must is a directory.'); | |
} | |
$absoluteSrcPath = realpath($src); | |
$absoluteDstPath = realpath($dst); | |
$dirname = basename($absoluteSrcPath); | |
$dstDirPath = $absoluteDstPath . '/' . $dirname; | |
if (!file_exists($dstDirPath)) { | |
mkdir($dstDirPath); | |
} | |
$files = scandir($absoluteSrcPath); | |
foreach ($files as $file) { | |
if ($file !== '.' && $file !== '..') { | |
$absoluteFilePath = $absoluteSrcPath . '/' . $file; | |
if (is_file($absoluteFilePath)) { | |
copy($absoluteFilePath, $dstDirPath . '/' . $file); | |
} else { | |
copyDir($absoluteFilePath, $dstDirPath); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment