File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -390,18 +390,27 @@ public function __clone()
390390
391391 protected function getBytes ($ value )
392392 {
393- $ value = trim ($ value );
394- switch (strtolower ($ value [strlen ($ value ) - 1 ]))
395- {
396- // The 'G' modifier is available since PHP 5.1.0
397- case 'g ' :
398- $ value *= 1024 ;
399- case 'm ' :
400- $ value *= 1024 ;
401- case 'k ' :
402- $ value *= 1024 ;
393+ preg_match ('/^\s*([0-9.]+(?:E\+\d+)?)\s*([KMGTPEZY]?)B?\s*$/i ' , $ value , $ matches );
394+
395+ $ number = (float ) $ matches [1 ];
396+ $ modifier = strtoupper ($ matches [2 ]);
397+
398+ $ exp_by_modifier = [
399+ 'K ' => 1 ,
400+ 'M ' => 2 ,
401+ 'G ' => 3 ,
402+ 'T ' => 4 ,
403+ 'P ' => 5 ,
404+ 'E ' => 6 ,
405+ 'Z ' => 7 ,
406+ 'Y ' => 8 ,
407+ ];
408+
409+ if (array_key_exists ($ modifier , $ exp_by_modifier )) {
410+ $ exp = $ exp_by_modifier [$ modifier ];
411+ $ number = $ number * pow (1024 , $ exp );
403412 }
404413
405- return $ value ;
414+ return $ number ;
406415 }
407416}
You can’t perform that action at this time.
0 commit comments