note 46581 rejected from function.filesize by aidan
| From: | aidan@php.net | Date: | Sat, 16 Oct 2004 01:29:04 +0000 |
| Subject: | note 46581 rejected from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78635@lists.php.net to get a copy of this message | ||
Note Submitter: gnif at spacevs dot com
----
I am reposting this code as I have descovered that people are ripping it off and caliming
authorship. This was removed from php.net and I have no idea why, the date of the original post was
02-Apr-2004 04:12:
Original Post:
=======================================
All the other functions I see on this page are just bloated if else statements, this is a nice and
neat function that will calculate all the way up to EB and more if you add them to the array $sizes.
function DownloadSize($file) {
$size = filesize($file);
$sizes = Array('B', 'KB', 'MB', 'GB', 'TB',
'PB', 'EB');
$ext = $sizes[0];
for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) {
$size = $size / 1024;
$ext = $sizes[$i];
}
return round($size, 2).$ext;
}
----
http://www.spacevs.com/index.php?page=phpsnippets
=======================================