note 46129 deleted from control-structures.switch by aidan
| From: | aidan@php.net | Date: | Thu, 30 Sep 2004 09:10:39 +0000 |
| Subject: | note 46129 deleted from control-structures.switch by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77609@lists.php.net to get a copy of this message | ||
Note Submitter: Flow
----
#this function returns you the filesize in Bytes, KB, MB, GB.
#$number must be the filesize in bytes
function byte2str($number, $position=2)
{
$base=1024;
$KB=pow($base, 1);
$MB=pow($base, 2);
$GB=pow($base, 3);
$numberstr = $number;
switch (true)
{
case ($number > $GB):
$numberstr /= $GB;
$end = "GB";
break;
case ($number > $MB):
$numberstr /= $MB;
$end = "MB";
break;
case ($number > $KB):
$numberstr /= $KB;
$end = "KB";
break;
default:
$end = "Byte";
break;
}
$temp = round($numberstr, $position);
$numberstr = $temp." ".$end;
return $numberstr;
}
#I hope this function can help you.