note 87285 added to function.filesize
| From: | xnavigator at osu1 dot php dot net | Date: | Fri, 28 Nov 2008 01:22:04 +0000 |
| Subject: | note 87285 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147056@lists.php.net to get a copy of this message | ||
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
----
Server IP: 80.241.173.254
Probable Submitter: 85.18.219.236
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/87285
Del: integrated -- https://master.php.net/note/delete/87285/integrated
Del: useless -- https://master.php.net/note/delete/87285/useless
Del: bad code -- https://master.php.net/note/delete/87285/bad+code
Del: spam -- https://master.php.net/note/delete/87285/spam
Del: non-english -- https://master.php.net/note/delete/87285/non-english
Del: in docs -- https://master.php.net/note/delete/87285/in+docs
Del: other reasons-- https://master.php.net/note/delete/87285
Reject -- https://master.php.net/note/reject/87285
Search -- https://master.php.net/manage/user-notes.php