note 49539 added to function.filesize
| From: | KOmaSHOOTER at gmx dot de | Date: | Tue, 01 Feb 2005 05:16:09 +0000 |
| Subject: | note 49539 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84301@lists.php.net to get a copy of this message | ||
<?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));
?>
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49539
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49539&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49539&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49539&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49539&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49539&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49539&report=yes
Search -- http://master.php.net/manage/user-notes.php