note 87285 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Sun, 18 Jan 2009 17:32:30 +0000 |
| Subject: | note 87285 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149395@lists.php.net to get a copy of this message | ||
Note Submitter: xnavigator
----
if I use the func of olafurw and d.abromeit
echo byteConvert(100);
// output: 100.00 B
And because we don't need of that .00 this is the correct func:
<?php
function byteConvert( $bytes ) {
if ($bytes<=0)
return '0 Byte';
$convention=1000; //[1000->10^x|1024->2^x]
$s=array('B', 'kB', 'MB', 'GB', 'TB',
'PB', 'EB', 'ZB');
$e=floor(log($bytes,$convention));
return round($bytes/pow($convention,$e),2).' '.$s[$e];
}
?>
you can simply switch from 10^x to 2^x changing $convention;
this func is a little faster because $e is calculated with only a log function