mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Move getHumanReadableDatasize() to functions
This commit is contained in:
@@ -203,33 +203,3 @@ function DisplayDashboard(&$extraFooterScripts)
|
||||
$extraFooterScripts[] = array('src'=>'app/js/linkquality.js', 'defer'=>false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a human readable data size string from a number of bytes.
|
||||
*
|
||||
* @param long $numbytes The number of bytes.
|
||||
* @param int $precision The number of numbers to round to after the dot/comma.
|
||||
* @return string Data size in units: PB, TB, GB, MB or KB otherwise an empty string.
|
||||
*/
|
||||
function getHumanReadableDatasize($numbytes, $precision = 2)
|
||||
{
|
||||
$humanDatasize = '';
|
||||
$kib = 1024;
|
||||
$mib = $kib * 1024;
|
||||
$gib = $mib * 1024;
|
||||
$tib = $gib * 1024;
|
||||
$pib = $tib * 1024;
|
||||
if ($numbytes >= $pib) {
|
||||
$humanDatasize = ' ('.round($numbytes / $pib, $precision).' PB)';
|
||||
} elseif ($numbytes >= $tib) {
|
||||
$humanDatasize = ' ('.round($numbytes / $tib, $precision).' TB)';
|
||||
} elseif ($numbytes >= $gib) {
|
||||
$humanDatasize = ' ('.round($numbytes / $gib, $precision).' GB)';
|
||||
} elseif ($numbytes >= $mib) {
|
||||
$humanDatasize = ' ('.round($numbytes / $mib, $precision).' MB)';
|
||||
} elseif ($numbytes >= $kib) {
|
||||
$humanDatasize = ' ('.round($numbytes / $kib, $precision).' KB)';
|
||||
}
|
||||
|
||||
return $humanDatasize;
|
||||
}
|
||||
|
Reference in New Issue
Block a user