PHP删除目录

PHP删除目录

// 参数 dir 目录路径
function rmrdir($dir) {
    $it = new RecursiveDirectoryIterator($dir);
    $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
    foreach($it as $file) {
        if ('.' === $file->getBasename() || '..' ===  $file->getBasename()) continue;
        if ($file->isDir() && ! $file->isLink()) rmdir($file->getPathname());
        else unlink($file->getPathname());
    }
    return rmdir($dir);
}
Posted in