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

R

roadrunner

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
 
A

A. Sinan Unur

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top