note 49539 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 13 Jul 2005 03:05:45 +0000 |
| Subject: | note 49539 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91844@lists.php.net to get a copy of this message | ||
Note Submitter: KOmaSHOOTER at gmx dot de
----
<?php
//******************* fixed example from cstretton *******************
// every data unit has a range of 2¹º = 1024 units ( 1 GB == 1024 MB )
// 1 Byte == 8 Bit
/* sources:
http://www.sengpielaudio.com/Rechner-bits.htm
http://de.freepedia.org/Megabyte.html
*/
function getfilesize($bytes) {
if ($bytes >= pow(2,40)) {
$return = round($bytes / pow(1024,4), 2);
$suffix = "TB";
} elseif ($bytes >= pow(2,30)) {
$return = round($bytes / pow(1024,3), 2);
$suffix = "GB";
} elseif ($bytes >= pow(2,20)) {
$return = round($bytes / pow(1024,2), 2);
$suffix = "MB";
} elseif ($bytes >= pow(2,10)) {
$return = round($bytes / pow(1024,1), 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Byte";
}
if ($return == 1) {
$return .= " " . $suffix;
} else {
$return .= " " . $suffix . "s";
}
return $return;
}
echo getfilesize(pow(2,30));
?>