-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstorage.php
26 lines (22 loc) · 874 Bytes
/
storage.php
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
<?php
$storage_path = ($cfg_array['storage_path']);
$storage_name = ($cfg_array['storage_name']);
/* get disk space free (in bytes) */
$df = disk_free_space($storage_path);
/* and get disk space total (in bytes) */
$dt = disk_total_space($storage_path);
/* now we calculate the disk space used (in bytes) */
$du = $dt - $df;
/* percentage of disk used - this will be used to also set the width % of the progress bar */
$dp = sprintf('%.2f', ($du / $dt) * 100);
/* and we format the size from bytes to MB, GB, etc. */
$df = formatSize($df);
$du = formatSize($du);
$dt = formatSize($dt);
function formatSize($bytes) {
$types = array('B', 'KB', 'MB', 'GB', 'TB');
for ($i = 0; $bytes >= 1024 && $i < ( count($types) - 1 ); $bytes /= 1024, $i++)
;
return( round($bytes, 2) . " " . $types[$i] );
}
echo "$storage_name: $du Used - $df Free - $dt Total";