Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

CGI - How to determine content length for multiple files ?

by roadrunner (Acolyte)
on Feb 06, 2006 at 11:05 UTC ( [id://528191]=perlquestion: print w/replies, xml ) Need Help??

roadrunner has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm using the CGI::upload_hook functionality to process multiple file uploads from a webpage and would like to provide users with status on the progress of the upload of each file - ideally a percentage figure of how much of the file content has been uploaded.

To do this, I need to know the size of each file before processing it in the hook. However, I notice that the only globally available indicator of the size of uploaded content seems to be:

$ENV{CONTENT_LENGTH};

...which gives the size for *all* uploaded files.

Does anyone know a way I can determine the size of each *individual* file ?

Thanks,
roadrunner

Replies are listed 'Best First'.
Re: CGI - How to determine content length for multiple files ?
by Adrade (Pilgrim) on Feb 06, 2006 at 12:53 UTC
    Retracted: Won't work with the upload-hook - sorry! :-)

    --
    By a scallop's forelocks!

Re: CGI - How to determine content length for multiple files ?
by cees (Curate) on Feb 06, 2006 at 15:17 UTC

    I don't believe that the content-length of each individual file is sent by the browsers, only a total content-length for the entire upload. That means you won't know the size of each file until it is uploaded.

    Your easiest solution is to just show the percentage of the entire upload that is finished, and then just update the name of the file that is currently being updated (which I believe the upload hook will pass to you). It might be nice to list all the files that have completed with the total size of each file as well.

    Last year I did a little playing around with providing a progress bar for file uploads that may be of interest to you. Not sure if it still works, since I haven't looked at it in a while, but all the source is there for you to hack on.

      Mmm, strange I have tried your http://cees.crtconsulting.ca/perl/examples/uploadmeter/ and strangely it does not work with my 1.5.0.1 Firefox (with javascript enabled...;-) , and works (a little) with an old IE...

      Pierre Couderc
Re: CGI - How to determine content length for multiple files ?
by santonegro (Scribe) on Feb 06, 2006 at 16:27 UTC
    Massive Data Aggregation with Perl by Fred Moyer shows how to do a mod-perl based upload and give the user constant feedback via Javascript. It's not the entire solution for you, but it should help. Good luck.
Re: CGI - How to determine content length for multiple files ?
by glasswalk3r (Friar) on Feb 06, 2006 at 15:20 UTC

    Based on the previous answer, you may want to try to separate each request to be attended by a different CGI::upload_hook CGI. Then you can fetch the results of those different request making requisitions to them using GET or using Ajax to do it.

    Anyway, doing like this looks like a great form of spending a lot of resources at the webserver. Maybe you should check which request size $ENV{CONTENT_LENGTH} shows and, hopefully being the biggest filesize, you should give a progress indicating how much time this file still needs to be processed until it finishes loading. Unless you're going to use Ajax (or any other technique to update the webpage without reloading it) it is useless to show the progress of each file being loaded.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://528191]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-12-07 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (50 votes). Check out past polls.