Add type-safe wrapper around MD_STD

This commit is contained in:
Joshua Ramon Enslin 2020-08-22 17:00:21 +02:00 committed by Stefan Rohde-Enslin
parent bac86627e2
commit 25b3138a26

View File

@ -284,6 +284,25 @@ class MD_STD {
}
/**
* Type-safe wrapper around filesize, if output is false, throws an error.
*
* @param string $filename File name.
*
* @return integer
*/
public static function filesize(string $filename):int {
$output = filesize($filename);
if ($output === false) {
throw new Exception("Cannot get filesize of file {$filename}");
}
return $output;
}
/**
* 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