1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-06 13:16:54 +02:00

Gelato: Number Class new method convertToBytes() added.

This commit is contained in:
Awilum
2014-01-29 20:40:22 +02:00
parent ceb19b2e83
commit 551ce3be6b

View File

@@ -47,6 +47,28 @@ class Number
return @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).' '.$unit[($i < 0 ? 0 : $i)];
}
/**
* Convert 'KB','MB','GB' in bytes
*
* <code>
* echo Number::convertToBytes('10MB');
* </code>
*
* @param string $num Number to convert
* @return int
*/
public static function convertToBytes( $num ) {
$size = strtolower( $size );
$bytes = (int) $size;
if ( strpos( $size, 'k' ) !== false )
$bytes = intval( $size ) * 1024;
elseif ( strpos( $size, 'm' ) !== false )
$bytes = intval($size) * 1024 * 1024;
elseif ( strpos( $size, 'g' ) !== false )
$bytes = intval( $size ) * 1024 * 1024 * 1024;
return $bytes;
}
/**
* Converts a number into a more readable human-type number.
*