public function testSize() { dir::make($this->tmpDir); f::write($this->tmpDir . DS . 'testfile-1.txt', str::random(5)); f::write($this->tmpDir . DS . 'testfile-2.txt', str::random(5)); f::write($this->tmpDir . DS . 'testfile-3.txt', str::random(5)); $this->assertEquals(15, dir::size($this->tmpDir)); $this->assertEquals('15 b', dir::niceSize($this->tmpDir)); dir::remove($this->tmpDir); }
public static function size($dir) { $handle = @opendir($dir); $size = 0; while (false !== ($f = readdir($handle))) { if ($f != "." && $f != "..") { if (is_dir("{$dir}/{$f}")) { $size += dir::size("{$dir}/{$f}"); } else { $size += filesize("{$dir}/{$f}"); } } } @closedir($handle); return $size; }
public function onSystem() { $header['title'] = '控制中心'; $phpinfo = array(); $server = $_SERVER['SERVER_ADDR'] . ' / ' . PHP_OS; $php = $_SERVER['SERVER_SOFTWARE']; $safemode = @ini_get('safe_mode') ? ' 开启' : '关闭'; if (@ini_get('file_uploads')) { $upload_max_filesize = ini_get('upload_max_filesize'); } else { $upload_max_filesize = '<b class="red">---</b>'; } $upload_filesize = format::byte(dir::size(ZOTOP_UPLOAD)); $database = zotop::db()->config(); $database['size'] = zotop::db()->size(); $database['version'] = zotop::db()->version(); $database['db'] = $database['hostname'] . ':' . $database['hostport'] . '/' . $database['database']; page::header($header); page::top(); page::navbar($this->navbar()); block::header('服务器信息'); table::header(); table::row(array('side 1 w60' => '服务器', 'main w300 1' => $server, 'side 2 w60 ' => 'WEB服务器', 'main 2' => $php)); table::row(array('side 1 w60' => '安全模式', 'main 1' => $safemode, 'side 2 w60 ' => 'PHP版本', 'main 2' => PHP_VERSION)); table::row(array('side 1 w60' => '程序版本', 'main 1' => zotop::config('zotop.version'), 'side 2 w60 ' => '程序根目录', 'main 2' => ROOT)); table::footer(); block::footer(); block::header('文件夹权限<span>如果某个文件或目录被检查到“无法写入”(以红色列出),请即刻通过 FTP 或其他工具修改其属性(例如设置为 777),以确保程序功能的正常使用</span>'); table::header(); table::row(array('side 1 w60' => '配置目录', 'main w300 1' => '', 'side 2 w60 ' => '备份目录', 'main 2' => '')); table::row(array('side 1 w60' => '运行目录', 'main w300 1' => '', 'side 2 w60 ' => '模块目录', 'main 2' => '')); table::footer(); block::footer(); block::header('数据库信息'); table::header(); table::row(array('side 1 w60' => '驱动名称', 'main w300 1' => $database['driver'], 'side 2 w60 ' => '数据库', 'main 2' => $database['db'])); table::row(array('side 1 w60' => '数据库版本', 'main 1' => $database['version'], 'side 2 w60 ' => '占用空间', 'main 2' => $database['size'])); table::footer(); block::footer(); block::header('文件上传'); table::header(); table::row(array('side 1 w60' => '上传许可', 'main w300 1' => $upload_max_filesize, 'side 2 w60 ' => '已上传文件', 'main 2' => '<span class="loading">' . $upload_filesize . '</span>')); table::footer(); block::footer(); page::bottom(); page::footer(); }