HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/posscale/subdomains/xibo/lib/Helper/ByteFormatter.php
<?php
/*
 * Spring Signage Ltd - http://www.springsignage.com
 * Copyright (C) 2015 Spring Signage Ltd
 * (ByteFormatter.php)
 */


namespace Xibo\Helper;

/**
 * Class ByteFormatter
 * @package Xibo\Helper
 */
class ByteFormatter
{
    /**
     * Format Bytes
     * http://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes
     * @param int $size The file size in bytes
     * @param int $precision The precision to go to
     * @param bool $si Use SI units or not
     * @return string The Formatted string with suffix
     */
    public static function format($size, $precision = 2, $si = false)
    {
        if ($size == 0)
            return 0;

        if ($si === false) {
            // IEC prefixes (binary)
            $suffixes = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
            $mod   = 1024;
            $base = log($size) / log($mod);
        } else {
            // SI prefixes (decimal)
            $suffixes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB');
            $mod   = 1000;
            $base = log($size) / log($mod);
        }

        return round(pow($mod, $base - floor($base)), $precision) . ' ' . $suffixes[(int)floor($base)];
    }

    /**
     * @param $val
     * @return int|string
     */
    public static function toBytes($val) {

        $val = trim($val);
        $last = strtolower($val[strlen($val)-1]);
        switch($last) {
            // The 'G' modifier is available since PHP 5.1.0
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }

        return $val;
    }
}