Last active
September 12, 2017 20:23
-
-
Save iksi/51dbb056d24d7c10de289a98e78e64e7 to your computer and use it in GitHub Desktop.
copy a directory and it's files recursively
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
<?php | |
function copyDirectory($sourceDirectory, $destinationDirectory) { | |
// determine the files that need to be copied | |
$files = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($sourceDirectory, FilesystemIterator::SKIP_DOTS) | |
); | |
foreach ($files as $file) { | |
$sourcePath = $file->getPathname(); | |
$destinationPath = $destinationDirectory . DS . $sourcePath; | |
// create the full path | |
if (!is_dir(dirname($destinationPath))) { | |
mkdir(dirname($destinationPath), 0755, true); | |
} | |
// finally copy the file | |
copy($sourcePath, $destinationPath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment