diff --git a/MD_STD.php b/MD_STD.php index 9ed4f00..f49055c 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -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