/*Copy xCopy function usage:
* xCopy("feiy","feiy2",1): Copy the files under feiy to feiy2, including subdirectories
* xCopy("feiy","feiy2",0): Copy the files under feiy to feiy2, no Include subdirectories
*Parameter description:
* $source: Source directory name
* $destination: Destination directory name
* $child: When copying, whether the subdirectory
is included * /
function xCopy($source, $destination, $child){
if (!file_exists($destination))
{
if (!mkdir(rtrim($destination, '/') , 0777))
) ;
}
if(!is_dir($source)){
return 0;
}
if(!is_dir($destination)){
mkdir($destination,0777 );
}
$handle=dir($source);
while($entry=$handle->read()){
if(($entry!=".") &&($entry!="..")){
if(is_dir($source."/".$entry)){
if($child)
xCopy($source."/ ".$entry,$destination."/".$entry,$child);
}
else{
copy($source."/".$entry,$destination."/". $entry);
}
}
}
return 1;
}
/* Delete deldir function usage:
* deldidr("feiy"): Delete feiy, including subdirectories * Parameter description:
* $dir: The name of the directory to be deleted
*/
function deldir($dir) {
if (!file_exists($dir)){return true;
}else{@chmod($dir, 0777);}
$ dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$ fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
deldir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
?>