|
Perforce Chronicle 2012.2/486814
API Documentation
|
Format a passed filesize in a friendlier manner. More...
Public Member Functions | |
| fileSize ($size, $precision=2) | |
| Takes the passed filesize and converts it to a friendlier format, such as: 12k 100M. | |
Static Protected Attributes | |
| static | $_suffixes = array('', 'K', 'M', 'G', 'T', 'P') |
Format a passed filesize in a friendlier manner.
| P4Cms_View_Helper_FileSize::fileSize | ( | $ | size, |
| $ | precision = 2 |
||
| ) |
Takes the passed filesize and converts it to a friendlier format, such as: 12k 100M.
| string | int | $size | the value to format |
| int | $precision | precision of the result; defaults to 2 |
{
$result = $size;
$index = 0;
while ($result > 1024 && $index++ < count(static::$_suffixes)) {
$result = $result / 1024;
}
// no fractions for less than 1K
if ($index == 0) {
return sprintf('%d B', $result);
}
return sprintf('%1.' . $precision . 'f %sB', $result, static::$_suffixes[$index]);
}
P4Cms_View_Helper_FileSize::$_suffixes = array('', 'K', 'M', 'G', 'T', 'P') [static, protected] |