mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-01-15 08:56:20 +01:00
46 lines
922 B
PHP
46 lines
922 B
PHP
<?php
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
/**
|
|
* Calculate the full size of a directory
|
|
*
|
|
* @param string $path
|
|
*/
|
|
function foldersize($path) {
|
|
$total_size = 0;
|
|
$files = scandir($path);
|
|
$cleanPath = rtrim($path, '/'). '/';
|
|
|
|
foreach($files as $t) {
|
|
if ($t<>"." && $t<>"..") {
|
|
$currentFile = $cleanPath . $t;
|
|
if (is_dir($currentFile)) {
|
|
$size = foldersize($currentFile);
|
|
$total_size += $size;
|
|
}
|
|
else {
|
|
$size = filesize($currentFile);
|
|
$total_size += $size;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $total_size;
|
|
}
|
|
|
|
|
|
function format_size($size) {
|
|
$units = explode(' ', 'B KB MB GB TB PB');
|
|
|
|
$mod = 1024;
|
|
|
|
for ($i = 0; $size > $mod; $i++) {
|
|
$size /= $mod;
|
|
}
|
|
|
|
$endIndex = strpos($size, ".")+3;
|
|
|
|
return substr( $size, 0, $endIndex).' '.$units[$i];
|
|
}
|
|
|
|
?>
|