note 55142 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:14:36 +0000 |
| Subject: | note 55142 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98295@lists.php.net to get a copy of this message | ||
Note Submitter: dejahvu at erols dot com
----
Here's a simple solution without a lot of code. I tried implementing the xB symbol with an
array, but I couldn't get it to print. Go figure. Using a switch works even though it's a
bit less efficient. Case 2 comes first because MB is the most likely size followed by KB in my
situation. No promises that this is bulletproof, but it suits my purposes as I'll never have a
file bigger than 2G.
$mysize=filesize($filename);
$counter=0;
while ($mysize > 1024) {$mysize=$mysize/1024; ++$counter;}
switch ($counter) {
case 2: $mysymbol="MB"; break;
case 1: $mysymbol="KB"; break;
case 0: $mysymbol="B"; break;
case 3: $mysymbol="GB"; break;
}
echo sprintf ("%01.1f %s", $mysize, $mysymbol); //($mysize.0 xB)
dej