php刪除與復(fù)制文件夾及其文件夾下所有文件的實(shí)現(xiàn)代碼
<?php
/*復(fù)制xCopy函數(shù)用法:
* xCopy("feiy","feiy2",1):拷貝feiy下的文件到 feiy2,包括子目錄
* xCopy("feiy","feiy2",0):拷貝feiy下的文件到 feiy2,不包括子目錄
*參數(shù)說(shuō)明:
* $source:源目錄名
* $destination:目的目錄名
* $child:復(fù)制時(shí),是不是包含的子目錄
*/
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;
}
/*刪除deldir函數(shù)用法:
* deldidr("feiy"):刪除feiy,包括子目錄
*參數(shù)說(shuō)明:
* $dir:要?jiǎng)h除的目錄名
*/
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;
}
}
?>
相關(guān)文章
php實(shí)現(xiàn)微信公眾平臺(tái)賬號(hào)自定義菜單類
這篇文章主要介紹了php實(shí)現(xiàn)微信公眾平臺(tái)賬號(hào)自定義菜單類的方法,涉及針對(duì)微信接口API的二次開發(fā),是非常實(shí)用的技巧,需要的朋友可以參考下2014-12-12mysql_escape_string()函數(shù)用法分析
這篇文章主要介紹了mysql_escape_string()函數(shù)用法,結(jié)合實(shí)例形式講述了mysql_escape_string()函數(shù)的功能,并分析了mysql_escape_string的使用技巧與注意事項(xiàng),需要的朋友可以參考下2016-04-04