[Javascript] Show a progress bar while waiting for a download to begin?

Frank Arensmeier frank.arensmeier at nikehydraulics.se
Fri Jun 9 15:31:18 CDT 2006


As a matter of fact, I saw today that I turned off error reporting  
for the redirect (why this row is still there, I don't know). PHP is  
giving me an error when I turn off error reporting. Since I have been  
working with this script a very long time, I must have forgotten  
that. I also checked which headers are actually send by the server.  
And, not very surprisingly, there is no redirect header - only the  
application header (which is different  - either application /pdf or  
application / octet - depending on which browser the user have).  
Sorry for not checking this  - my fault/laziness.

This is what I got from "Live HTTP Headers":

http://xxxxxxxxxx/products/pdfDownload/11_1149883265_sv.pdf

GET /products/pdfDownload/11_1149883265_sv.pdf HTTP/1.1
Host: xxx.xxx.xxx.xxx
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; sv-SE; rv: 
1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/ 
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: sv,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://xxx.xxx.xxx.xxx/downloads/downloads_leaflets_sv.php
Cookie: lastvisit=23; image=32; language=sv

HTTP/1.x 200 OK
Date: Fri, 09 Jun 2006 20:01:18 GMT
Server: Apache/1.3.33 (Darwin) PHP/5.1.4 mod_ssl/2.8.24 OpenSSL/0.9.7i
X-Powered-By: PHP/5.1.4
Content-Length: 403449
content-disposition: attachment; filename=11_1149883265_sv.pdf
Connection: close
Content-Type: application/pdf
----------------------------------------------------------

  I think I will have a closer look at how to speed up the script and  
if I can make use of flushing the output buffer. After all, investing  
time and work in writing a script for a progress / wait-until-the- 
document-is-ready bar maybe isn't worth the effort.

/thank you so far

9 jun 2006 kl. 18.04 skrev Nick Fitzsimons:

> Frank Arensmeier wrote:
>> On one of my pages users can download dynamically generated PDF  
>> documents by clicking on a normal <a> link. Generating a PDF  
>> document would usually take between three and six seconds. When  
>> the document is ready, it will be downloaded automatically (the  
>> document will not be shown in the browser) by sending an  
>> "application/*octet*-*stream*" header. When the server begins  
>> outputting the document, it also sends a redirect to the original  
>> page.
>
> This won't work because it's not how HTTP works. If you return the  
> requested resource (the generated PDF), that's a status 200  
> response, and once you've started that response you can't change  
> it. You can't piggyback two responses (a "200 OK" and a "302 Moved  
> Temporarily", which is what a redirect is) in one. See
>
> <http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1>
>
> I'm surprised PHP doesn't throw an exception when you try to do  
> this. I presume that, having sent response headers such as Content- 
> Type, PHP is then ignoring any future attempt to change the HTTP  
> status from 200 to 302; alternatively it's just going to throw away  
> the generated response and only send the redirect. It sound like  
> it's doing the first.
>
> Certainly, no browser is going to know what to do with a response  
> with two status lines, as it's a breach of the standard. Browsers  
> (strictly speaking, user agents) are, I believe, entitled to simply  
> terminate the whole request-response transaction upon receiving  
> something as malformed as this would be if it _did_ have two status  
> lines.
>
> Have you had a look at the raw HTTP traffic?
>
> FWIW, when I go to download a file, the browser takes over and  
> displays a dialog asking if I want to open or save the file,  
> followed by another dialog with a progress bar (IE/Win) or a  
> progress bar in the Download Manager dialog (Firefox, Opera,  
> Safari). Any script in your page has no access to that information.
>
> If your problem is the few seconds it takes for the server to  
> prepare the response, after which the user should see the browser's  
> download dialog, you might be able to remove the wait by setting  
> your response headers, then flushing the response so far (I'm no  
> PHP expert, but I believe the flush() method might do it), and then  
> doing the PDF generation. By the time the user has looked blankly  
> at the dialog and selected "Save" or "Open" at random (assuming a  
> typical use ;-) your server-side code should be a good way along to  
> generating the content.
>
> P.S. See
> <http://uk2.php.net/manual/en/function.flush.php>
> for details of PHP's flush() function and various gotchas.
>
> HTH,
>
> Nick.
> -- 
> Nick Fitzsimons
> http://www.nickfitz.co.uk/
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>



More information about the Javascript mailing list