php刪除與復(fù)制文件夾及其文件夾下所有文件的實現(xiàn)代碼
<?php
/*復(fù)制xCopy函數(shù)用法:
* xCopy("feiy","feiy2",1):拷貝feiy下的文件到 feiy2,包括子目錄
* xCopy("feiy","feiy2",0):拷貝feiy下的文件到 feiy2,不包括子目錄
*參數(shù)說明:
* $source:源目錄名
* $destination:目的目錄名
* $child:復(fù)制時,是不是包含的子目錄
*/
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ù)說明:
* $dir:要刪除的目錄名
*/
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基于curl post實現(xiàn)發(fā)送url及相關(guān)中文亂碼問題解決方法
這篇文章主要介紹了PHP基于curl post實現(xiàn)發(fā)送url及相關(guān)中文亂碼問題解決方法,結(jié)合具體實例形式分析了php使用curl實現(xiàn)post數(shù)據(jù)發(fā)送及content-type相關(guān)設(shè)置操作技巧,需要的朋友可以參考下2017-11-11
淺析Dos下運行php.exe,出現(xiàn)沒有找到php_mbstring.dll 錯誤的解決方法
本篇文章是對在Dos下運行php.exe,出現(xiàn)沒有找到php_mbstring.dll 錯誤的解決方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06

