Hello, proxomos:
There are several ways to do that, here is one version:
function my_copy($oldname, $newname)
{
if(is_file($oldname)){
$perms = fileperms($oldname);
return copy($oldname, $newname) && chmod($newname, $perms);
}
else if(is_dir($oldname)){
my_dir_copy($oldname, $newname);
}
else{
die("Cannot copy file: $oldname (it's neither a file nor a directory)");
}
}
function my_dir_copy($oldname, $newname)
{
if(!is_dir($newname)){
mkdir($newname);
}
$dir = opendir($oldname);
while($file = readdir($dir)){
if($file == "." || $file == ".."){
continue;
}
my_copy("$oldname/$file", "$newname/$file");
}
closedir($dir);
}
You can use my_copy, which copies recursively the contents of one dir
into a target dir.
As I say, there are several ways to do it, so feel free to request for
any clarification.
Regards. |