PHP 遞歸刪除目錄中文件
阿新 • • 發佈:2017-08-01
lena closed close open true pub stat sed $path
/**
* 遞歸刪除目錄中文件
* @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;
}
PHP 遞歸刪除目錄中文件