Browser download without a Content-Length header?
July 20, 2006 9:47 AM
Subscribe
How do I get the browser to prompt a user to save a huge file when I don't know it's size in advance?
I'm generating a large file on the fly and streaming it to the user's browser. When the download starts I want them to be prompted to save the file. Usually you can just set the Content-Length header to make this happen but because I'm building the file as it's transmitted, I don't know the length ahead of time.
When Content-Length isn't set, the behavior of both IE and Firefox is to download the entire file, then prompt the user to save it. This means that the browser sits there a long time spinning it's little spinner and probably making the user think nothing is happening.
Currently I'm setting Content-Type and Content-Disposition. If I do Content-Length="2147483647" (eg. 232, the save prompt comes up properly but says it expects 2GB of data and will take 100s of hours to complete.
I know I've seen Firefox send a file to the download manager without knowing it's size. How do you do it?
posted by joegester to technology (9 comments total)
header("Content-Transfer-Encoding: binary");
header("Content-Type: " . $mimetype);
header("Content-Disposition: attachment; filename=\"" . $name .
"\";" );
posted by null terminated at 10:42 AM on July 20, 2006