mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-31 02:28:35 +08:00
Fix #19526: Add the convertIniSizeToBytes method to BaseStringHelper
This commit is contained in:
@ -52,6 +52,30 @@ class BaseStringHelper
|
||||
return mb_substr((string)$string, $start, $length, '8bit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts php.ini style size to bytes.
|
||||
*
|
||||
* @param string $string php.ini style size. Examples: `512M`, `1024K`, `1G`, `256`.
|
||||
* @return int the number of bytes equivalent to the specified string.
|
||||
* @since 2.0.54
|
||||
*/
|
||||
public static function convertIniSizeToBytes($string)
|
||||
{
|
||||
switch (substr($string, -1)) {
|
||||
case 'M':
|
||||
case 'm':
|
||||
return (int) $string * 1048576;
|
||||
case 'K':
|
||||
case 'k':
|
||||
return (int) $string * 1024;
|
||||
case 'G':
|
||||
case 'g':
|
||||
return (int) $string * 1073741824;
|
||||
default:
|
||||
return (int) $string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the trailing name component of a path.
|
||||
* This method is similar to the php function `basename()` except that it will
|
||||
|
||||
Reference in New Issue
Block a user