<?php
namespace Engine\Smarty\Modifiers; class FormatFileSize { static public function create($size, $decimals=1) { $sizes = ['B','KB','MB','GB','TB','PB']; $factor = floor((strlen($size) - 1) / 3); return sprintf("%.{$decimals}f %s", $size / pow(1024, $factor), $sizes[$factor]); } }