CGI.pm - How to determine content length for multiple files ?

Discussion in 'Perl Misc' started by roadrunner, Feb 6, 2006.

  1. roadrunner

    roadrunner Guest

    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 by providing 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 prior to entering the hook ?

    Thanks,
    roadrunner
     
    roadrunner, Feb 6, 2006
    #1
    1. Advertising

  2. "roadrunner" <> wrote in news:1139231932.944164.20590
    @z14g2000cwz.googlegroups.com:

    > 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 by providing 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 prior to entering the hook ?


    This is what the CGI.pm documentation has to say:

    When a file is uploaded the browser usually sends along some information
    along with it in the format of headers. The information usually includes
    the MIME content type. Future browsers may send other information as well
    (such as modification date and size). To retrieve this information, call
    uploadInfo(). It returns a reference to an associative array containing all
    the document headers.

    $filename = param('uploaded_file');
    $type = uploadInfo($filename)->{'Content-Type'};
    unless ($type eq 'text/html') {
    die "HTML FILES ONLY!";
    }

    Sinan
     
    A. Sinan Unur, Feb 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,632
    SkyUCHC
    Jun 9, 2010
  2. Replies:
    4
    Views:
    957
    M.E.Farmer
    Feb 13, 2005
  3. Janto Dreijer

    multiple content-types break cgi.py

    Janto Dreijer, Mar 4, 2007, in forum: Python
    Replies:
    4
    Views:
    333
    Jon Ribbens
    Mar 4, 2007
  4. Peña, Botp
    Replies:
    1
    Views:
    242
    Robert Klemme
    Jan 24, 2004
  5. Rick DeNatale
    Replies:
    9
    Views:
    162
    Clifford Heath
    Jan 25, 2008
Loading...

Share This Page