Use integer for first param of human_filesize

This commit is contained in:
Joshua Ramon Enslin 2020-08-11 08:10:23 +02:00 committed by Stefan Rohde-Enslin
parent 08c9582210
commit b8d8be54b9

View File

@ -288,15 +288,15 @@ class MD_STD {
* Function human_filesize translates byte-level filesizes to human readable ones. * Function human_filesize translates byte-level filesizes to human readable ones.
* Thanks to Jeffrey Sambells http://jeffreysambells.com/2012/10/25/human-readable-filesize-php * Thanks to Jeffrey Sambells http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
* *
* @param string $bytes A file size, e.g. returned from filesize(). * @param integer $bytes A file size, e.g. returned from filesize().
* @param integer $decimals Number of decimal digits to allow. * @param integer $decimals Number of decimal digits to allow.
* *
* @return string * @return string
*/ */
public static function human_filesize(string $bytes, int $decimals = 2):string { public static function human_filesize(int $bytes, int $decimals = 2):string {
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$factor = floor((strlen($bytes) - 1) / 3); $factor = floor((strlen((string)$bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $size[$factor]; return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $size[$factor];
} }