MOD: Let computer know filesize of the files it's downloading.

Right now, when someone tries to download some file from an order. The computer is unable to tell how much further it has to go. For example:







Here’s my fix:



In “/core/fn_common.php”, add the 2 parts in red below:



[COLOR=Red]//
// Get the file or directory size
//
function getsize($file) {
if (!is_dir($file)) {
return filesize($file);
}
$size = 0;
foreach (scandir($file) as $f) {
if ($f == '.' or $f == '..') {
continue;
}
$size += getsize($file . '/' . $f);
}
return $size;
}[/COLOR]

//
// Download the file
//
function fn_get_file($path, $disposition_filename='', $encode_name=false, $content_disposition="attachment")
{
$file = basename($path);
$fd = fopen($path, 'r');
if ($fd) {
header("Content-type: application/octet-stream");
if (!$disposition_filename) {
$disposition_filename = $file;
}
// If file name contains non latin simbols than it should be encoded for Internet Explorer
if ($encode_name) {
$disposition_filename = rawurlencode($disposition_filename);
}
header("Content-disposition: $content_disposition; filename=\"$disposition_filename\"");
[COLOR=Red]header("Content-Length: " . getsize($path) . "\n");[/COLOR]
while (!feof($fd)) {
echo(fread($fd, 3000)); // Read by 3k blocks to avoid memory leaks
fn_flush();
}
exit();
}
}
The result is this: