Re: filesize math
| From: | tg-php at gryffyndevelopment dot com | Date: | Fri, 24 Dec 2004 11:02:32 +0000 |
| Subject: | Re: filesize math | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-205134@lists.php.net to get a copy of this message | ||
Well, depends on your definition of a kb, mb, gb, etc..
You seem to be mixing definitions here.
One school of thought is that...
1000 bytes = 1 kb
1000 kb = 1 mb
1000 mb = 1 gb
In reality...
1024 bytes = 1 kb
1024 kb = 1 mb
1024 mb = 1 gb
You're checking filesize against the '1000' method then you're returning a
number based on the '1024' method.
You should always be consistant across the board.
-TG
= = = Original message = = =
i made this function and want to know if i am doing the math correctly..
seems to be caculating ok.. $filesize is in bytes.. if the filesize is under
1MB i want to show KBs, if its under 1GB i want to show MB, if its over
1000MB i want to show GB, makes sense? ;)
function byte_format($filesize)
if ($filesize < 1000000)
return number_format($filesize / 1024, 2, '.', '') . ' KB';
else if($filesize > 1000000000)
return number_format($filesize / 1024 / 1024 / 1024, 2, '.', '') .
' GB';
else
return number_format($filesize / 1024 / 1024, 2, '.', '') . '
MB';
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.