note 88053 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Sun, 18 Jan 2009 17:32:18 +0000 |
| Subject: | note 88053 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149394@lists.php.net to get a copy of this message | ||
Note Submitter: digitaldoener AT googlemail DOT com
----
Hi,
this is my very fast version of byteConvert(). Without using costly pow() function.
<?php
/**
* Byte converting with bitshifting and formated number
*
* @param int $bytes bytes
* @return string
*/
function byteConvert(&$bytes){
$con = 1024;
$b = (int)$bytes;
$s = array('B', 'kB', 'MB', 'GB', 'TB');
$e = (int)(log($b,$con));
return number_format($b/($con<<$e)*2,2,',','.').' '.$s[$e];
}
?>