PHP 递归删除目录中文件
2021-06-17 05:05
标签:pen 中文 rmdir static closed add func path close PHP 递归删除目录中文件 标签:pen 中文 rmdir static closed add func path close 原文地址:http://www.cnblogs.com/l-zl/p/7267142.html/**
* 递归删除目录中文件
* @param $pathname
* @return bool
*/
public static function delDir($pathname)//要删除的目录
{
if(file_exists($pathname)) {
if(is_file($pathname)) {
unlink($pathname);
} else {
$dir = opendir($pathname);
while($filename = readdir($dir)) {
if($filename != "." && $filename != "..") {
$filename = $pathname . "/" . $filename;
if(is_dir($filename)) {
self::delDir($filename);
} else {
unlink($filename);
}
}
}
closedir($dir);
rmdir($pathname);
}
}
return true;
}