note 55142 added to function.filesize

From: Date: Tue, 26 Jul 2005 13:29:17 +0000
Subject: note 55142 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-92483@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55142 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55142&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55142&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92483) next »