Back to MediaHelper class

Method toBytes

public int
toBytes
(mixed $val)
Small helper function that properly converts any configuration options to their byte representation.
Parameters
  • string|int $val The value to be converted to bytes.
Returns
  • int The calculated bytes value from the input.
Since
  • 3.3
Class: MediaHelper
Project: Joomla

Method toBytes - Source code

/**
 * Small helper function that properly converts any
 * configuration options to their byte representation.
 *
 * @param   string|integer  $val  The value to be converted to bytes.
 *
 * @return integer The calculated bytes value from the input.
 *
 * @since 3.3
 */
public function toBytes($val)
{
    switch ($val[\strlen($val) - 1]) {
        case 'M':
        case 'm':
            return (int) $val * 1048576;
        case 'K':
        case 'k':
            return (int) $val * 1024;
        case 'G':
        case 'g':
            return (int) $val * 1073741824;
        default:
            return $val;
    }
}