2015-09-11 20:45:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Formater
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
|
|
|
class Formater
|
|
|
|
{
|
|
|
|
public static function humanSize($size, $precision = 2)
|
|
|
|
{
|
|
|
|
$base = log($size, 1024);
|
2016-05-09 23:08:44 +02:00
|
|
|
$suffixes = array('B', 'kB', 'MB', 'GB', 'TB');
|
2015-09-11 20:45:54 +02:00
|
|
|
|
|
|
|
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
|
|
|
}
|
|
|
|
}
|