php递归删除缓存文件

时间:2020-04-16 14:53:07   收藏:0   阅读:54
/**
     * 递归删除缓存文件
     * @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);
    }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!