note 99513 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Fri, 20 Aug 2010 20:54:16 +0000 |
| Subject: | note 99513 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171906@lists.php.net to get a copy of this message | ||
Note Submitter: rasenplanscher
----
Nice elegant function, that. I added the option to give precision as an argument. Also, I split the
second return into two lines, because I like my code a little more readable. Thusly, my flavor of
format_size:
<?php
format_size($size, $precision = 0) {
$units = array('Bytes', 'KB', 'MB', 'GB', 'TB',
'PB', 'EB', 'ZB', 'YB');
if ($size == 0)
return 'n/a';
else {
$scale = floor(log($size, 1024));
return round($size/pow(1024, $scale), $i > 1 ? $precision : 0).$units[$scale];
}
}
?>