-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunction.php
More file actions
37 lines (32 loc) · 1021 Bytes
/
Copy pathfunction.php
File metadata and controls
37 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
xoops_loadLanguage('main', 'tadtools');
$inSchoolWeb = is_link(XOOPS_ROOT_PATH . '/mainfile.php') ? true : false;
function GetDirectorySize($path)
{
// 如果路徑不存在,直接回傳 0
if (!file_exists($path)) {
return 0;
}
// 使用遞迴計算資料夾大小,取代原本的 popen/du 方式
return folderSize($path);
}
function folderSize($dir)
{
$size = 0;
try {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)) as $file) {
$size += $file->getSize();
}
} catch (UnexpectedValueException $e) {
// 目錄無法讀取就跳過
}
return $size;
}
function format_size($bytes = '')
{
$si_prefix = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$base = 1024;
$class = min((int) log($bytes, $base), count($si_prefix) - 1);
$space = sprintf('%1.2f', $bytes / pow($base, $class)) . ' ' . $si_prefix[$class];
return $space;
}