Dir::delDir PHP Method

delDir() public method

+---------------------------------------------------------- 删除目录(包括下面的文件) +---------------------------------------------------------- +---------------------------------------------------------- +----------------------------------------------------------
public delDir ( $directory, $subdir = true )
    public function delDir($directory, $subdir = true)
    {
        if (is_dir($directory) == false) {
            exit('The Directory Is Not Exist!');
        }
        $handle = opendir($directory);
        while (($file = readdir($handle)) !== false) {
            if ($file != '.' && $file != '..') {
                is_dir("{$directory}/{$file}") ? Dir::delDir("{$directory}/{$file}") : unlink("{$directory}/{$file}");
            }
        }
        if (readdir($handle) == false) {
            closedir($handle);
            rmdir($directory);
        }
    }

Usage Example

Beispiel #1
0
 public function cache()
 {
     if (isset($_GET['type'])) {
         $Dir = new \Dir();
         $cache = D('Common/Cache');
         $type = I('get.type');
         switch ($type) {
             case "template":
                 //删除缓存目录下的文件
                 $Dir->del(RUNTIME_PATH);
                 $Dir->delDir(RUNTIME_PATH . "Cache/");
                 $Dir->delDir(RUNTIME_PATH . "Temp/");
                 //更新开启其他方式的缓存
                 \Think\Cache::getInstance()->clear();
                 $this->success("模板缓存清理成功!", U('Index/cache'));
                 break;
             case "logs":
                 $Dir->delDir(RUNTIME_PATH . "Logs/");
                 $this->success("站点日志清理成功!", U('Index/cache'));
                 break;
             default:
                 $this->error("请选择清楚缓存类型!");
                 break;
         }
     } else {
         $this->display();
     }
 }
All Usage Examples Of Dir::delDir