 |
Title: Bytes Scale function Marked Cool (Review this resource) Author: silence Posted On: 2004-11-29 Category: Home > PHP Functions
Popularity:
Description: Returns the nearest prefix (k, M, G) for $bytes (given parameter).
Page Navigation: [1]
Bytes Scale function
This function calculates the nearest prefix for bytes in kilobits (KB), megabits (MB) or gigabits (GB).
Code is:
<?
//
// Returns 10 raised to the power of $exp.
//
function pow10($exp)
{
return pow(10, $exp);
}
//
// Returns the nearest prefix for $bytes
//
function bytes_scale($bytes)
{
if ($bytes < pow10(3) )
return $bytes.' B';
elseif ($bytes >= pow10(3) && $bytes < pow10(6) )
return round($bytes/pow10(3), 2).' kB';
elseif ($bytes >= pow10(6) && $bytes < pow10(9) )
return round($bytes/pow10(6), 2).' MB';
else
return round($bytes/pow10(9), 2).' GB';
}
?>
by Bartek Nowotarski
Page Navigation: [1]
|
|
 |