php deletes and copies the implementation code for folders and all files under them
- 2020-05-27 04:38:22
- OfStack
<?php
/* copy xCopy Function usage:
* xCopy("feiy","feiy2",1): copy feiy The following file arrives feiy2, Including subdirectories
* xCopy("feiy","feiy2",0): copy feiy The following file arrives feiy2, Subdirectories are not included
* Parameter description:
* $source: The source directory name
* $destination: Destination directory name
* $child: Copy is not contained when subdirectories
*/
function xCopy($source, $destination, $child){
if (!file_exists($destination))
{
if (!mkdir(rtrim($destination, '/'), 0777))
{
//$err->add($_LANG['cannt_mk_dir']);
return false;
}
@chmod($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 directory name to delete
*/
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);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
?>