Latte\Runtime\Filters::bytes PHP Method

bytes() public static method

Converts to human readable file size.
public static bytes ( $bytes, $precision = 2 ) : string
return string plain text
    public static function bytes($bytes, $precision = 2)
    {
        $bytes = round($bytes);
        $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
        foreach ($units as $unit) {
            if (abs($bytes) < 1024 || $unit === end($units)) {
                break;
            }
            $bytes = $bytes / 1024;
        }
        return round($bytes, $precision) . ' ' . $unit;
    }

Usage Example

Beispiel #1
0
 public function getPanel()
 {
     $buff = '<h1>AssetsLoader</h1>' . '<div class="nette-inner">' . '<table>' . '<thead><tr><th>Source</th><th>Generated file</th><th>Memory usage</th></tr></thead>';
     $i = 0;
     foreach ($this->files as $source => $generated) {
         $buff .= '<tr><th' . ($i % 2 ? 'class="nette-alt"' : '') . '>' . $source . '</th><td>' . $this->link($generated['id'], $generated['type'], $generated['lastModified']) . '</td><td>' . Runtime\Filters::bytes($generated['memory']) . '</td></tr>';
     }
     return $buff . '</table></div>';
 }
All Usage Examples Of Latte\Runtime\Filters::bytes