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

First time question here. Using Win32 Perl. I have written a file upload script that gets processed with CGI.pm. I am trying to create a progress bar that monitors the overall upload of 1 or more files. I believe that CGI::upload_hook() is just what I am looking for but have had a devil of a time find any good examples to work off of. And the existing docmentation has left me pretty confused.

My understanding is that if called, CGI.pm will loop the upload_hook() module until the entire file upload is completed, but while looped, the &hook sub routine will process what ever I need to be processed - in this case the passing over vars to another script or out to a text file that can be read by another script that is being processed in a pop-up window.

1) Am i even on the right track?
2) Where do I define CGI::upload_hook(\&hook,$data); ? Before or after "use CGI;", before or after "$query = new CGI'" ?
3) What is $data, it gets passed in AND is passed right back out - what is its value supposed to be going in and what does &hook use it for. Whats the value of it when it gets passed out?

My upload script works just fine, its trying to get this progress bar to work that is killing me.

Thank you oh wise ones!

Replies are listed 'Best First'.
Re: Understanding CGI::upload_hook() ;
by cees (Curate) on Aug 19, 2005 at 19:58 UTC

    I have a working example of an upload meter script that you can have a look at. It uses some AJAX calls to update the webpage of the progress. You can try it out at the following URL:

    http://cees.crtconsulting.ca/perl/examples/uploadmeter/

    There is a link to a tarball containing all the code to get it running on that page as well.

    It uses the CGI.pm upload hook to manage the upload, so it should give you some good hints on how to get it going in your script.

      I downloaded the .tar but there was an error unzipping it with WinZip.

        Odd. There is nothing wrong with the tar file, as I can untar and gunzip it no problem. I have placed a zipped version up there, maybe that will work for you. Or just browse the files online.

        Hope that helps

        Update: Apache was gzipping the output since I had the DEFLATE filter on. Renamed the file to .tar.gz and added 'RemoveOutputFilter DEFLATE' to apache conf. I have updated the links in the parent thread so it should all be working now.