/**
  * 清空系统缓存目录
  * **/
 public function clearCache($type = 'img')
 {
     $arr = array();
     // $rutimepath = str_replace(MODULE_NAME . '/', '', RUNTIME_PATH);
     //图片目录缓存
     // 		if ($type == 'data' || $type == 'all') {
     // 			$arr[] = del_allfile(STYLE_CACHE_DIR);
     // 			$arr[] = del_allfile(IMAGE_CACHE_DIR);
     // 		}
     // //数据目录缓存
     // 		if ($type == 'run' || $type == 'all') {
     // 			$arr[] = del_allfile(RUNTIME_PATH);
     // 		}
     $arr[] = del_allfile('./Data/cache/');
     //运行时目录缓存
     if (is_array($arr)) {
         //统计缓存大小
         $siz = 0;
         foreach ($arr as $aa) {
             foreach ($aa as $aaa) {
                 $siz += $aaa['size'];
             }
         }
         $this->success("缓存已经清理完成,共计 " . $siz / 1000 . " k", '', 6);
     }
 }
Exemple #2
0
function del_allfile($fpath, $delself = false, $delfolder = true)
{
    defined('YPATH') or define('YPATH', $fpath);
    $files = array();
    $filepath = iconv('gb2312', 'utf-8', $fpath);
    if (is_dir($fpath)) {
        if ($dh = opendir($fpath)) {
            while (($file = readdir($dh)) !== false) {
                if ($file != '.' && $file != '..') {
                    $temarr = del_allfile($fpath . '/' . $file);
                    $files = array_merge($files, $temarr);
                }
            }
            closedir($dh);
        }
        if ($delfolder) {
            //过虑删除自己的情况
            if ($fpath === YPATH) {
                if ($delself) {
                    $files[] = array('path' => $fpath, 'size' => filesize($fpath));
                    @rmdir($fpath);
                }
            } else {
                $files[] = array('path' => $fpath, 'size' => filesize($fpath));
                @rmdir($fpath);
            }
        }
    } else {
        if (is_file($fpath)) {
            $files[] = array('path' => $fpath, 'size' => filesize($fpath));
            @unlink($fpath);
        }
    }
    return $files;
}