note 62114 deleted from function.filesize by nlopess
| From: | nlopess@php.net | Date: | Wed, 01 Mar 2006 10:58:21 +0000 |
| Subject: | note 62114 deleted from function.filesize by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-104620@lists.php.net to get a copy of this message | ||
Note Submitter: darkness at bgdev dot org
----
a fix for
mazaki at shaw dot ca's functions.
The original function showed GB as MB, and MB as Kb and so on, so the fix is very simple, just
remove the Bytes from the $units array
<?php
function human_size( $bytes, $decimal = '2' ) {
if( is_numeric( $bytes ) ) {
$position = 0;
$units = array(" KB", " MB", " GB", " TB" );
while( $bytes >= 1024 && ( $bytes / 1024 ) >= 1 ) {
$bytes /= 1024;
$position++;
}
return round( $bytes, $decimal ) . $units[$position];
}
else {
return "0 Bytes";
}
}
?>