protected static function xcopy($source, $destination, $permissions = 0755)
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $destination);
}
// Simple copy for a file
if (is_file($source)) {
return copy($source, $destination);
}
// Make destination directory
if (!is_dir($destination)) {
mkdir($destination, $permissions);
}
// Loop through the folder
$dir = dir($source);
while (false !== ($entry = $dir->read())) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
self::xcopy($source . DIRECTORY_SEPARATOR . $entry, $destination . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return true;
}