note 97305 deleted from function.filesize by danbrown

From: Date: Tue, 13 Apr 2010 14:06:27 +0000
Subject: note 97305 deleted from function.filesize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168197@lists.php.net to get a copy of this message
Note Submitter: te at sky-networx dot de ---- Another "3-line solution" to format the filesize in a readable format: <?php /** * Converts a filesize in bytes to a human readable string * * @param $iBytes integer expects a filesize in bytes * @return string formatted string (eg.: 1,30 MB) * @access public * @static **/ public static function format_size($iBytes) { $aUnits = array('bytes', 'kb', 'MB', 'GB', 'TB', 'PB'); $iSize = floor(log($iBytes)/log(1024)); return sprintf('%.2f '.$aUnits[$iSize], ($iBytes/pow(1024, floor($iSize)))); } ?>

« previous php.notes (#168197) next »