You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
789 B
25 lines
789 B
<?php |
|
|
|
declare(strict_types=1); |
|
|
|
/** |
|
* 获取文件夹体积 |
|
*/ |
|
function FunGetDirSize($dir) |
|
{ |
|
clearstatcache(); |
|
$dh = opendir($dir) or exit('打开目录错误'); //打开目录,返回一个目录流 |
|
$size = 0; //初始大小为0 |
|
while (false !== ($file = @readdir($dh))) { //循环读取目录下的文件 |
|
if ($file != '.' and $file != '..') { |
|
$path = $dir . '/' . $file; //设置目录,用于含有子目录的情况 |
|
if (is_dir($path)) { |
|
$size += FunGetDirSize($path); //递归调用,计算目录大小 |
|
} elseif (is_file($path)) { |
|
$size += filesize($path); //计算文件大小 |
|
} |
|
} |
|
} |
|
closedir($dh); //关闭目录流 |
|
return $size; //返回大小 |
|
}
|
|
|