note 55121 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:14:30 +0000 |
| Subject: | note 55121 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98294@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I wanted human readable filesizes as well, but solved it little easier with code a newbie can modify
:)
function GetReadableFileSize($path) {
$filesize = filesize($path);
$unit = "bytes";
if ($filesize > 1024) {
$filesize = ($filesize / 1024);
$unit = "kB"; }
if ($filesize > 1024) {
$filesize = ($filesize / 1024);
$unit = "MB"; }
if ($filesize > 1024) {
$filesize = ($filesize / 1024);
$unit = "GB"; }
if ($filesize > 1024) {
$filesize = ($filesize / 1024);
$unit = "TB"; }
$filesize = round($filesize, 0);
return $filesize." ".$unit;
}
With this function in an include or somewhere you can write GetReadableFileSize($path); anywhere you
want.