PHP递归删除缓存文件

    /**
     * 递归删除缓存文件
     * @param $dir 缓存文件路径
     */
    function delFileByDir($dir) {
        $dh = opendir($dir); 
        while ($file = readdir($dh)) {
            if ($file != "." && $file != "..") {
                $fullpath = $dir . "/" . $file;
                if (is_dir($fullpath)) {
                    $this->delFileByDir($fullpath);
                } else {
                    unlink($fullpath);  
                }
            }  
        }
        closedir($dh);
    }

 

posted @ 2020-04-16 14:28  张喜龙  阅读(163)  评论(0编辑  收藏  举报