Skip to content

Commit

Permalink
Fix notice in function toBytes()
Browse files Browse the repository at this point in the history
Fix notice "A none well formed numeric value" caused in function toBytes().

Close gh-34.
  • Loading branch information
dimayakovlev committed Aug 13, 2021
1 parent bc7fcfd commit ba12664
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions admin/inc/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,23 @@ function get_site_version($echo = true) {

/**
* Convert to Bytes
* Convert M/G/K byte string to bytes
*
* @since 3.0
* @since 3.5.0 Fix notice
*
* @param $str string
* @return string
* @param mixed $str
* @return mixed
*/
function toBytes($str) {
$val = trim($str);
$last = strtolower($str[strlen($str)-1]);
switch($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
}
if (is_numeric($str)) return (int)$str;
$val = (int)trim($str, 'gmkGMK');
$last = strtolower($str[strlen($str) - 1]);
switch ($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
}
return $val;
}

Expand Down

0 comments on commit ba12664

Please sign in to comment.