note 103237 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Apr 2011 14:25:32 +0000 |
| Subject: | note 103237 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178478@lists.php.net to get a copy of this message | ||
Note Submitter: ban at n dot as
----
class Size
{
static $bytes = 1024;
static $unit =
array('Bytes','KB','MB','GB','TB','QB');
public static function unit($bytes,$i = 0)
{
$i = 0;
while(1)
{
if(!$i) $size = $bytes;
else $size = $size/self::$bytes;
if($size < self::$bytes) break;
$i++;
}
return round($size,2).' '.self::$unit[$i];
}
public static function bytes($unit)
{
$value = preg_replace('/[A-Z]/i','',$unit);
$unit = str_replace($value,'',$unit);
if(!$unit) return $value;
for($i=0;$i<count(self::$unit);$i++)
{
if(strtolower($unit) == strtolower(self::$unit[$i])) break;
$value = $value * self::$bytes;
}
return $value;
}
}