note 97305 added to function.filesize
| From: | te at sky-networx dot de | Date: | Tue, 13 Apr 2010 12:22:16 +0000 |
| Subject: | note 97305 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168195@lists.php.net to get a copy of this message | ||
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))));
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 84.156.116.162
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/97305
Del: integrated -- https://master.php.net/note/delete/97305/integrated
Del: useless -- https://master.php.net/note/delete/97305/useless
Del: bad code -- https://master.php.net/note/delete/97305/bad+code
Del: spam -- https://master.php.net/note/delete/97305/spam
Del: non-english -- https://master.php.net/note/delete/97305/non-english
Del: in docs -- https://master.php.net/note/delete/97305/in+docs
Del: other reasons-- https://master.php.net/note/delete/97305
Reject -- https://master.php.net/note/reject/97305
Search -- https://master.php.net/manage/user-notes.php