note 48497 deleted from function.filesize by aidan

From: Date: Wed, 13 Jul 2005 03:06:06 +0000
Subject: note 48497 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-91846@lists.php.net to get a copy of this message
Note Submitter: cstretton at gmail dot com ---- 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; } ?>

« previous php.notes (#91846) next »