note 10102 added to filesize

From: Date: Wed, 13 Dec 2000 21:04:57 +0000
Subject: note 10102 added to filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-8708@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]); http://www.php.net/manual/function.filesize.php

« previous php.notes (#8708) next »