note 10102 deleted from function.filesize by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:16:10 +0000 |
| Subject: | note 10102 deleted from function.filesize by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22716@lists.php.net to get a copy of this message | ||
I like eric@schorvitz.com improvement on how to build more human readable file size strings, but
won't it fail at file sizes of 0 Bytes? Seems like the extensions calculation ($ext[$j-1])
would fail as $ext[0-1].
I use:
$size = filesize(<FILENAME>);
$exp = 1;
while($size >= pow(1024, $exp))
{
$exp++;
}
$ext = array("B", "KB", "MB", "GB", "TB");
$summary = round(($size * 100) / pow(1024, ($exp - 1))) / 100;
$strsize = sprintf("%.2f%s", $summary, $ext[$exp - 1]);