Snippet for formatting byte size.
Usage:
formatSize(‘12345′);
*********** UPDATE **********
From LogicEarth at Sitepoint, an alternative method
Cheers LE
function fromBytes ( $size, $place = 3, $iec = true, $bits = false )
{
$messure = ‘KMGTPXZY’;
$factor = $iec ? 1024 : 1000;
$count = 0;
{
$messure = ‘KMGTPXZY’;
$factor = $iec ? 1024 : 1000;
$count = 0;
if ($bits) { $size *= 8; }
while ( $size >= $factor ) {
$size /= $factor; $count++;
}
$messure = $count ? $messure[ –$count ] . ( $iec ? ‘i’ : ” ) : ”;
$messure = !$bits ? $messure . ‘B’ : strtolower( $messure ) . ‘b’;
return round( $size, $place ) . ‘ ‘ . $messure;
}
July 10th, 2008 at 1:58 pm
Good site..keep up the work
July 16th, 2008 at 12:16 am
Thought you might like another byte formatting function
But not sure how to do code here, so pastebin ^^;
http://pastebin.com/f7644dd4d