note 99831 deleted from function.filesize by danbrown
| From: | danbrown@php.net | Date: | Thu, 09 Sep 2010 14:24:52 +0000 |
| Subject: | note 99831 deleted from function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172421@lists.php.net to get a copy of this message | ||
Note Submitter: sunlight dot architect at gmail dot com
----
re a human-readable filesize function, PHP remembers the index from a for loop, so you could just do
something like this:
<?php
function file_size ($filename)
{
$type = array ('bytes', 'kilobytes', 'megabytes',
'gigabytes', 'terabytes');
$filesize = filesize ($filename);
for ($i = 0; $filesize > 1024; $i++)
$filesize /= 1024;
return round ($filesize, 2) . ' ' . $type[$i];
}
?>