use recursive traversal instead of scandir function
This commit is contained in:
parent
f9f6b5168a
commit
148b03b512
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-02-03 14:39:50
|
* @Date: 2016-02-03 14:39:50
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-03-19 10:08:11
|
* @Last Modified time: 2016-03-19 12:53:18
|
||||||
*/
|
*/
|
||||||
require "../includes/session.inc.php";
|
require "../includes/session.inc.php";
|
||||||
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
|
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
|
||||||
|
|
@ -36,7 +36,7 @@ $db = new Database\Database();
|
||||||
<span class="info-box-icon bg-green"><i class="fa fa-files-o"></i></span>
|
<span class="info-box-icon bg-green"><i class="fa fa-files-o"></i></span>
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">上传材质总数</span>
|
<span class="info-box-text">上传材质总数</span>
|
||||||
<span class="info-box-number"><?php echo count(scandir("../textures/"))-2;?></span>
|
<span class="info-box-number"><?php echo Utils::getFileNum(BASE_DIR."/textures/");?></span>
|
||||||
</div><!-- /.info-box-content -->
|
</div><!-- /.info-box-content -->
|
||||||
</div><!-- /.info-box -->
|
</div><!-- /.info-box -->
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ $db = new Database\Database();
|
||||||
<span class="info-box-icon bg-yellow"><i class="fa fa-hdd-o"></i></span>
|
<span class="info-box-icon bg-yellow"><i class="fa fa-hdd-o"></i></span>
|
||||||
<div class="info-box-content">
|
<div class="info-box-content">
|
||||||
<span class="info-box-text">占用空间大小</span>
|
<span class="info-box-text">占用空间大小</span>
|
||||||
<span class="info-box-number"><?php echo floor(Utils::getDirSize("../textures/")/1024)."KB";?></span>
|
<span class="info-box-number"><?php echo floor(Utils::getDirSize(BASE_DIR."/textures/")/1024)."KB";?></span>
|
||||||
</div><!-- /.info-box-content -->
|
</div><!-- /.info-box-content -->
|
||||||
</div><!-- /.info-box -->
|
</div><!-- /.info-box -->
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-01-16 23:01:33
|
* @Date: 2016-01-16 23:01:33
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-03-19 09:52:51
|
* @Last Modified time: 2016-03-19 12:55:08
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
|
|
@ -73,22 +73,47 @@ class Utils
|
||||||
* @return int, total size in bytes
|
* @return int, total size in bytes
|
||||||
*/
|
*/
|
||||||
public static function getDirSize($dir) {
|
public static function getDirSize($dir) {
|
||||||
$dh = opendir($dir);
|
$resource = opendir($dir);
|
||||||
$size = 0;
|
$size = 0;
|
||||||
while(false !== ($file = @readdir($dh))) {
|
while($filename = readdir($resource)) {
|
||||||
if ($file!='.' && $file!='..') {
|
if ($filename != "." && $filename != "..") {
|
||||||
$path = $dir.'/'.$file;
|
$path = $dir.$filename;
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
$size += $this->getDirSize($path);
|
// recursion
|
||||||
|
$size += self::getDirSize($path);
|
||||||
} else if (is_file($path)) {
|
} else if (is_file($path)) {
|
||||||
$size += filesize($path);
|
$size += filesize($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dh);
|
closedir($resource);
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively count files of specified directory
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
* @param $file_num
|
||||||
|
* @return int, total size in bytes
|
||||||
|
*/
|
||||||
|
public static function getFileNum($dir, $file_num = 0) {
|
||||||
|
$resource = opendir($dir);
|
||||||
|
while($filename = readdir($resource)) {
|
||||||
|
if ($filename != "." && $filename != "..") {
|
||||||
|
$path = $dir.$filename;
|
||||||
|
if (is_dir($path)) {
|
||||||
|
// recursion
|
||||||
|
$file_num = self::getFileNum($path, $file_num);
|
||||||
|
} else {
|
||||||
|
$file_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($resource);
|
||||||
|
return $file_num;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple SQL injection protection
|
* Simple SQL injection protection
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user