First off, thank you to those who were nice enough to help me in my last thread. This is sort of a continuation - even tho that problem was solved, a new one has popped up.
I have a custom script that automatically generates a unique download key, and then gets saved to a MySQL database that I have created. This is to prevent customers from discovering the location of the actual download file.
I have everything setup and working just fine. I go to my generatekey page, get a key (d/l link), c&p into a browser, and the file d/ls just fine - unless the file is too large. I am not sure what the tolerance is, but I can say that a file of only a few megs will d/l fine each and every time. A file over 250 MB will not - occasionally it d/ls fine, but more often then not, it doesn't. And the result varies. A 266 MB file I am currently testing with will wind up being 212 MB, 245 MB, 249 MB, 231 MB on four consecutive d/ls. Each of those d/ls is a unique key. I called my host to see if I was running in to some limit, but was informed that the limit is 1 GB/file, so that is not the issue. Breaking up the file into smaller chunks is not an option; the file is a .rar file that already is part of a larger file. It's 3 GB, which ultimately I want to break down into 6 500 MB files.
So, I have no problem posting code, but I am not really sure what to post here. I will start with the end of my d/l.php:
Code:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($fakefilename) .'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($realfilename));
ob_clean();
flush();
readfile($realfilename);
exit;
}
}
}
?>
Do not know if that is of any use, but again, not sure what would be. So, I do some searching around, and I find this:
http://www.php.net/manual/en/function.header.php#86554
--edit--- Hmmmm....for some reason, clicking that link does not bring you to the correct part of the page, but a c&p will. Here is what it says:
--------------
For large files (100+ MBs), I found that it is essential to flush the file content ASAP, otherwise the download dialog doesn't show until a long time or never.
<?php
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
?>
--------------
I tried playing with that code, but wasn't sure is I did everything I needed to. For ex., I changed:
Code:
header('Content-Length: ' . filesize($realfilename));
...but there are some other things I wasn't sure about. Like:
Code:
$fp = fopen($file, "r");
Then the other thing is, at the top it says, "I found that it is essential to flush the file content ASAP, otherwise the download dialog doesn't show until a long time or never." Well, that sounds like it fixes a problem of the d/l dial not showing - which is not the problem I have. So I wonder that, even if I do get the code from this page 100% correct, if that is really the fix.
Can anyone offer any suggestions as to where to look? Any advice will be greatly appreciated. Thank you!