php 批量删除文件夹

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/85988566
//删除文件
function deldir($dir)
{
    //先删除目录下的文件
    $dh = opendir($dir);
    while ($file = readdir($dh)) {
        if ($file != "." && $file != "..") {
            $fullpath = $dir . "/" . $file;
            if (!is_dir($fullpath)) {
                unlink($fullpath);
            } else {
                deldir($fullpath);
            }
        }
    }

    closedir($dh);
//删除当前文件夹;
    if(rmdir($dir)){
        return true;
    }else{
        return false;
    }
}

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/85988566