Php implements code for deleting and copying all files in folders and their folders. Copy the code as follows :? Php * copy xCopy function usage: * xCopy (feiy, feiy2, 1): copy the file in feiy to feiy2, including the sub-directory * xCopy (feiy, feiy2, 0 ): copy files under feiy
The code is as follows:
/* Copy the xCopy function usage:
* XCopy ("feiy", "feiy2", 1): copy the files in feiy to feiy2, including subdirectories.
* XCopy ("feiy", "feiy2", 0): copy the file under feiy to feiy2, excluding subdirectories.
* Parameter description:
* $ Source: source directory name
* $ Destination: target directory name
* $ Child: indicates whether to include sub-directories during replication.
*/
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"): deletes feiy, including subdirectories.
* Parameter description:
* $ Dir: 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 );
} Else {
Deldir ($ fullpath );
}
}
}
Closedir ($ dh );
If (rmdir ($ dir )){
Return true;
} Else {
Return false;
}
}
?>
The http://www.bkjia.com/PHPjc/326538.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326538.htmlTechArticle code is as follows :? Php/* copy xCopy function usage: * xCopy ("feiy", "feiy2", 1): Copy files under feiy to feiy2, including sub-directories * xCopy ("feiy ", "feiy2", 0): copy the file under feiy...