Small script, being used to send one of two .pdf files to the user based on the get string:
if ($fileToSend == "bigone") {
$filename = "largefile.pdf";
$header = "application/pdf";
} else if ($fileToSend == "smallone") {
$filename = "smallfile.pdf";
$header = "application/pdf";
}
if (file_exists('d/' . $filename)){
header('Content-type: ' . $header);
header('Content-disposition: attachment; filename=' . $filename);
readfile('d/' . $filename);
} else {
echo('No good');
}
Both files d/smallfile.pdf and d/largefile.pdf exist. smallfile.pdf is about 5megs. largefile.pdf is about 25megs.
sendFile.php?fileToSend=smallone works.
sendFile.php?fileToSend=bigone doesn’t work; in FF, it says
File not found
Firefox can’t find the file at [url]/sendFile.php?fileToSend=bigone
There are no filename errors.
I’ve tried
- Adding flush(); prior to the readfile; this causes the download file dialogue box to appear, but then serves a 0 byte file
- Adding flush(); prior to the readfile, and adding header(‘Content-Length: ‘ . filesize(‘d/’ . $filename)); – this works successfully, but takes close to 2 minutes to process (ie, once I hit the URL, nothing happens for close to 2 minutes, and then the dialogue box appears with the actual file to download in it correctly).
Any help would be much appreciated.
Jon
Yes your problem is most likely php timing out while feeding you the file, a remedy for this is to feed you chunks so as not to chew memory and
set_time_limit(0);so it wont timeout after 60s: