You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
captainkuro edited this page Jan 10, 2013
·
6 revisions
Copy a directory (and its contents) recursively. The best way to use this would be to extend the directory helper because it uses the directory_map method. Or, you could load the directory helper and whatever helper this function would be in.
<?php/** * Copy a whole Directory * * Copy a directory recrusively ( all file and directories inside it ) * * @access public * @param string path to source dir * @param string path to destination dir * @return array */if(!function_exists('directory_copy'))
{
functiondirectory_copy($srcdir, $dstdir)
{
//preparing the paths$srcdir=rtrim($srcdir,'/');
$dstdir=rtrim($dstdir,'/');
//creating the destination directoryif(!is_dir($dstdir))mkdir($dstdir, 0777, true);
//Mapping the directory$dir_map=directory_map($srcdir);
foreach($dir_mapas$object_key=>$object_value)
{
if(is_numeric($object_key))
copy($srcdir.'/'.$object_value,$dstdir.'/'.$object_value);//This is a File not a directoryelsedirectory_copy($srcdir.'/'.$object_key,$dstdir.'/'.$object_key);//this is a directory
}
}
}