Fix a non well formatted numeric value encountered & Notice: Undefined offset in `fm_get_filesize()` (#681)

For non `well formatted numeric value encountered`, see #670
For `Notice: Undefined offset 9` (current implementation result) see: https://3v4l.org/1qHit#v5.0.0
For new impementation result, see: https://3v4l.org/d0UBh#v5.0.0
This commit is contained in:
Suyadi 2021-12-13 11:45:09 +07:00 committed by GitHub
parent 95d41a9518
commit 08cb4b0fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -2501,7 +2501,8 @@ function fm_get_filesize($size)
{ {
$size = (float) $size; $size = (float) $size;
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0; $power = ($size > 0) ? floor(log($size, 1024)) : 0;
$power = ($power > (count($units) - 1)) ? (count($units) - 1) : $power;
return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]); return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]);
} }