note 84652 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 17:38:46 +0000 |
| Subject: | note 84652 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153355@lists.php.net to get a copy of this message | ||
Note Submitter: php-manual at gone dot nl
----
Based on Maikels function.
Improved performance (10 - 15%) and added Doc-block
<?php
/**
* Present a size (in bytes) as a human-readable value
*
* @param int $size size (in bytes)
* @param int $precision number of digits after the decimal point
* @return string
*/
function bytestostring($size, $precision = 0) {
$sizes = array('YB', 'ZB', 'EB', 'PB', 'TB',
'GB', 'MB', 'kB', 'B');
$total = count($sizes);
while($total-- && $size > 1024) $size /= 1024;
return round($size, $precision).$sizes[$total];
}
?>