At 17:27 12.11.2002, Kenn Murrah spoke out and said:
--------------------[snip]--------------------
>Can anyone point me in the direction of a Javascript code snippet that would 
>display a progress bar for a PHP upload?  I'm sure it can be done that way, 
>but honestly, I lack the Javascript skills to make it happen ....  
--------------------[snip]-------------------- 

If I understood you correctly you want to accomplish something like

a) you have a file upload form
b) user clicks "upload", and a progress meter is displayed
c) when the upload is done, the progress meter will be at 100% and vanish
or tell "finished" or something like that

I'm afraid this cannot be done very easily. What you'd need to know at the
moment the user clicks on "upload" would be the actual filesize, and the
average transmission speed so you can estimate the pace to go from 0 to
100. And, you need both values at the client's, a server side script is not
yet active at this time.

I'd suggest to take the easy road (seen on a couple of other sites)...
Create an animated gif with a progress bar constantly scrolling. In your
form's "onSubmit()" method (at the client's side!), do a window.open() with
the appropriate parameters to generate a small window without any controls,
sized sufficiently to just contain this gif.

The URL of this popup would be a PHP script (with the same session ID of
the uploader) which would basically do this:

    if (!$_SESSION['popup_opened']) {
        $_SESSION['popup_opened'] = true;
        send_popup_html();
    }
    elseif (!$_SESSION['xmit_done'])
        header('HTTP/1.0 204 No Content');
    else send_close_html();

send_popup_html would add a header to refresh the popup:
    header('Refresh: 1;
URL=http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']?SID);

send_close_html would simply send html like
    <body onload='window.close();'>

I hope you get the idea... Basically the crucial stuff is the refresh
header for the popup url that causes the client to _try_ to refresh every
second. As long as the transfer is not finished, the popup script simply
replies with "204 No Content", so the browser would change nothing with the
popup. When the upload is eventually finished, the refresh request
succeeds, but the only stuff the client receives is a javascript closing
the popup...


-- 
   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
    ^ http://www.vogelsinger.at/

Reply via email to