CGI::POST_MAX Question...

G

George Magklaras

In an attempt to control the file upload size on a PERL 5.6.1 CGI
script, I used my own counters to set the maximum size of the file to
around 4 MBytes. So I had my traditional while loop that looks like
this (inside a subroutine):

sub UploadFile {

..
..
..
my $buffersize = 65_536;
my $maxBuffers = 64;
..
..
..
while(read( $fh, $buffer, $buffersize)) {
$cnter++;
if ($cnter <= $maxBuffers) {
print UPLOAD $buffer;
} else {
$returnData = 'uploaded file too big';
return $returnData;
}
..
..
..
}

The subroutine works. it starts uploading the file and then when the
file goes over 4MBytes, it drops out...Which is fine, but some people
may have extremely low-speed connections, so it may take some time to
discover that after waiting 10-20 minutes to upload the 4 Megs, they
cannot continue. Hence, what I really want is to know the size of the
file to-be-uploaded before hand.

I am wearing CGI::Corp and CGI::Safe and I read that CGI::pOST_MAX can
also be used to limit the size of the HTTP POST operation. The
questions I have are:
1)Does this happen at the very beginning of the POST operation, or
right after the file has already occupied 4Mbytes of RAM/Disk space.
What I want is to prevent the operation from the very beginning if the
file exceeds 4Megs.
2)If the answer to the previous question is 'No, it happens at the
end.', does someone now of a reliable (aka browser independent way) to
'probe' the size of the file-to-be-uploaded from the very beginning?

Regards,
George Magklaras
 
S

simonis

George said:
(...)

The
questions I have are:
1)Does this happen at the very beginning of the POST operation, or
right after the file has already occupied 4Mbytes of RAM/Disk space.
What I want is to prevent the operation from the very beginning if the
file exceeds 4Megs.
2)If the answer to the previous question is 'No, it happens at the
end.', does someone now of a reliable (aka browser independent way) to
'probe' the size of the file-to-be-uploaded from the very beginning?

You'll probably find better answers in a group whose topic matter is
more relevant to these questions. comp.infosystems.www.authoring.cgi
might be a good fit.

-Ds
 
Z

zentara

In an attempt to control the file upload size on a PERL 5.6.1 CGI
script, I used my own counters to set the maximum size of the file to
around 4 MBytes. So I had my traditional while loop that looks like
this (inside a subroutine):
sub UploadFile {
my $buffersize = 65_536;
my $maxBuffers = 64;
while(read( $fh, $buffer, $buffersize)) {
$cnter++;
if ($cnter <= $maxBuffers) {
print UPLOAD $buffer;
} else {
$returnData = 'uploaded file too big';
return $returnData;
}

Try something like this to check the Content-Length first.

Right at the top of your script:

if($ENV{CONTENT_LENGTH} > $maxsize){
print "file too large - must be less than $maxsize bytes";
exit;
}
 

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
474,125
Messages
2,570,748
Members
47,301
Latest member
SusannaCgx

Latest Threads

Top