mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-39524 setuplib: Improve get_real_size() performance and readability
This commit is contained in:
parent
03b8b55f10
commit
ddf98ccac3
1 changed files with 15 additions and 18 deletions
|
@ -1327,26 +1327,23 @@ function get_real_size($size = 0) {
|
||||||
if (!$size) {
|
if (!$size) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$scan = array();
|
|
||||||
$scan['GB'] = 1073741824;
|
|
||||||
$scan['Gb'] = 1073741824;
|
|
||||||
$scan['G'] = 1073741824;
|
|
||||||
$scan['MB'] = 1048576;
|
|
||||||
$scan['Mb'] = 1048576;
|
|
||||||
$scan['M'] = 1048576;
|
|
||||||
$scan['m'] = 1048576;
|
|
||||||
$scan['KB'] = 1024;
|
|
||||||
$scan['Kb'] = 1024;
|
|
||||||
$scan['K'] = 1024;
|
|
||||||
$scan['k'] = 1024;
|
|
||||||
|
|
||||||
while (list($key) = each($scan)) {
|
static $binaryprefixes = array(
|
||||||
if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
|
'K' => 1024,
|
||||||
$size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
|
'k' => 1024,
|
||||||
break;
|
'M' => 1048576,
|
||||||
}
|
'm' => 1048576,
|
||||||
|
'G' => 1073741824,
|
||||||
|
'g' => 1073741824,
|
||||||
|
'T' => 1099511627776,
|
||||||
|
't' => 1099511627776,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (preg_match('/^([0-9]+)([KMGT])/i', $size, $matches)) {
|
||||||
|
return $matches[1] * $binaryprefixes[$matches[2]];
|
||||||
}
|
}
|
||||||
return $size;
|
|
||||||
|
return (int) $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue