note 48497 added to function.filesize
| From: | cstretton at gmail dot com | Date: | Sun, 26 Dec 2004 21:30:38 +0000 |
| Subject: | note 48497 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82331@lists.php.net to get a copy of this message | ||
The function below doesn't work properly for files below 1kb, heres a fixed one.
<?php
// Returns a nicely formatted filesize from a number of bytes
function getfilesize($bytes) {
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = "TB";
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = "GB";
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = "MB";
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Byte";
}
if ($return == 1) {
$return .= " " . $suffix;
} else {
$return .= " " . $suffix . "s";
}
return $return;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48497
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48497&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48497&report=yes
Search -- http://master.php.net/manage/user-notes.php