Website bug: File sizes wrong

From: Date: Tue, 03 Apr 2001 23:26:46 +0000
Subject: Website bug: File sizes wrong
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-4645@lists.php.net to get a copy of this message
http://www.php.net/downloads.php The links aren't matched with accurately file sizes. The Win32 binary package is 3.7Kb with everything in it, but a whopping 735Kb *without* installer, extensions and more of that package. And the complete source has GOT to be bigger than 2.4K... :) The problem is in download_link() in /include/layout.inc. Here's a (maybe) better version you might want to adopt. It scales the number down to [0,1024[ and affixes an appropriate measure prefix. For completeness, I've put in prefixes up to a yottabyte to allow for future expansion of the mind-blowing type! ;^) ================================================== function download_link($file, $title) { global $filesizes, $server; if ($tmp = strrchr($file, "/")) { $local_file = substr($tmp, 1, strlen($tmp)); } else { $local_file = "distributions/$file"; } $size = @filesize($local_file); // echo("<!-- file=$file localfile=$local_file size-$size -->\n"); if (!$size && isset($filesizes[$local_file])) { $size = $filesizes[$local_file]; } $suffixes = array("byte", "bytes", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"); $precision = array("0", "0", "0", "1", "3", "3", "3", "3", "3", "3"); $power = ($size == 1) ? 0 : 1; while ($size >= 1024) { $power++; $size /= 1024; } print_link("http://www.php.net/do_download.php?download_file=" . $file . "&source_site=$server", $title); if ($size) { echo " [" . number_format($size, $precision[$power], ",", ".") . " " . $suffixes[$power] . "]"; } } Stay frosty! Michael ---- Michael Chowet | Tel: +1.(514)-287-1166 Configuration Manager | Direct: +1.(514)-287-8934 ext. 237 Critical Mass Labs Inc. | Fax: +1.(514)-287-3360 (formerly MathEngine Canada Inc.) | 465 McGill Street, First Floor | http://www.cm-labs.com Montreal, Qc H2Y 2H1 CANADA | michael.chowet@cm-labs.com

« previous php.mirrors (#4645) next »