1. public function fileSizeFilter($size)
    2. {
    3. $currentValue = $currentUnit = null;
    4. $unitExps = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3);
    5. foreach ($unitExps as $unit => $exp) {
    6. $divisor = pow(1000, $exp);
    7. $currentUnit = $unit;
    8. $currentValue = $size / $divisor;
    9. if ($currentValue < 1000) {
    10. break;
    11. }
    12. }
    13. return sprintf('%.1f', $currentValue).$currentUnit;
    14. }