note 101400 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Wed, 15 Dec 2010 00:16:15 +0000 |
| Subject: | note 101400 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174927@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
bconvert(345324535345); // return: 321 Gb 623 Mb 143 Kb 561 b
function bconvert($bytes)
{
static $typetext = array('Kb','Mb', 'Gb', 'Tb');
static $typesize = array(1024, 1048576, 1073741824, 1099511627780);
$num = 3;
$total_txt = '';
$cur_num = 0;
$success = 0;
while(true)
{
if($typesize[$num] <= $bytes)
{
$bytes -= $typesize[$num];
$cur_num++;
$success = 1;
}
else
{
if($success)
{
$total_txt .= $cur_num.' '.$typetext[$num].' ';
$cur_num = 0;
$success = 0;
}
$num--;
if($typesize[0] > $bytes)
{
if($bytes != 0)
$total_txt .= $bytes.' b';
break;
}
}
}
return $total_txt;
}