mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-07 21:56:39 +02:00
Gelato: Number Class new method convertToBytes() added.
This commit is contained in:
@@ -47,6 +47,28 @@ class Number
|
|||||||
return @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).' '.$unit[($i < 0 ? 0 : $i)];
|
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.
|
* Converts a number into a more readable human-type number.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user