note 55654 added to function.filesize
| From: | sleek at osu1 dot php dot net | Date: | Tue, 09 Aug 2005 19:08:56 +0000 |
| Subject: | note 55654 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93334@lists.php.net to get a copy of this message | ||
I altered the function to be a little more flexible. Thanks for the good code
<?php
function format_filesize($filesize)
{
$units = array('B', 'KB', 'MB', 'GB', 'TB',
'PB', 'EB', 'ZB', 'YB');
$tot_units = count($units);
$pass = 0; // set zero, for Bytes
// Keep calculating until we are past the known unit size
while ($filesize >= 1024 && $pass <= $tot_units) {
$filesize /= 1024;
$pass++;
}
// If we are past the last unit, then make our pass equal the last one
if ($pass > $tot_units) {
$pass = $tot_units - 1;
}
return round($filesize, 2).' '.$units[$pass];
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55654
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55654&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55654&report=yes
Search -- http://master.php.net/manage/user-notes.php