PHP implementation code to delete and copy a folder and all files under the folder_PHP tutorial

WBOY
Release: 2016-07-21 15:13:03
Original
782 people have browsed it

Copy code The code is as follows:

/*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;
}
}
?>





http://www.bkjia.com/PHPjc/326538.htmlwww.bkjia.com

truehttp: //www.bkjia.com/PHPjc/326538.htmlTechArticleThe copy code code is as follows: ?php /*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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template