php递归删除缓存文件

/**
     * 递归删除缓存文件
     * @param $dir 缓存文件路径
     */
    public 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);
    }
原文地址:https://www.cnblogs.com/zhangxilong/p/12712674.html