PHP 删除目录及目录下文件

原文链接: http://www.cnblogs.com/laowenBlog/p/6067945.html

<?php

function del_dir ($dir,$type=true)
{
    $n=0;
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if ( $file == '.' or $file =='..')
                {
                    continue;
                }
                if (is_file ($dir.$file))
                {
                    unlink($dir.$file);
                    $n++;
                }
                if (is_dir ($dir.$file))
                {
                    del_dir ($dir.$file.'/');
                    if ($type)
                    {
                        $n++;
                        rmdir($dir.$file.'/');
                    }
                }
            }
        }
        closedir($dh);
    }
    return $n;
}

?>

转载于:https://www.cnblogs.com/laowenBlog/p/6067945.html

猜你喜欢

转载自blog.csdn.net/weixin_30745641/article/details/94799563