public static function sizeToBytes($str)
    {
        if (!preg_match('/^(\d+(\.\d+)?)([bkmg]*)$/i', trim($str), $parts)) {
            throw new \Exception('Failed to convert string to bytes, incorrect size given: ' . $str);
        }

        switch (substr(strtolower($parts[3]), 0, 1)) {
            case 'g':
                $size = (int)($parts[1] * 1073741824);
                break;
            case 'm':
                $size = (int)($parts[1] * 1048576);
                break;
            case 'k':
                $size = (int)($parts[1] * 1024);
                break;
            case 'b':
            default:
                $size = (int)$parts[1];
                break;
        }

        return $size;
    }