php 删除文件夹及文件夹内文件函数

/** delDir()删除文件夹及文件夹内文件函数
* @param string $path 文件夹路径
* @param string $delDir 是否删除改
* @return boolean
*/
function delDir($path, $del = false){
$handle = opendir($path);
if ($handle) {
while (false !== ($item = readdir($handle))) {
if (($item != ".") && ($item != "..")) {
is_dir("$path/$item") ? delDir("$path/$item", $del) : unlink("$path/$item");
}
}

closedir($handle);

if ($del) {
return rmdir($path);
}
}elseif (file_exists($path)) {
return unlink($path);
}else {
return false;
}
}

posted @ 2018-06-07 18:31  jierong  阅读(2473)  评论(0编辑  收藏  举报