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;
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM