Skip to content

Instantly share code, notes, and snippets.

@lleitep3
Created June 7, 2011 14:57
Show Gist options
  • Save lleitep3/1012415 to your computer and use it in GitHub Desktop.
Save lleitep3/1012415 to your computer and use it in GitHub Desktop.
copy a folder
<?php
function copyDir($source,$destination)
{
if(!is_dir($destination))
mkdir($destination, 0777);
chmod($destination, 0777);
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source),
\RecursiveIteratorIterator::SELF_FIRST);
$it->next();
while($it->valid()){
if(!$it->isDot())
if($it->isFile())
copy($it->getRealPath(), $destination.$it->getSubPathname());
else
mkdir($destination.$it->getSubPathname(), 0777, true);
$it->next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment