CGI::POST_MAX Question...

  • Follow


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

0
Reply George 8/12/2003 1:53:39 PM

George Magklaras wrote:
> 

(...)

>                                                           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
0
Reply simonis 8/12/2003 4:03:45 PM


On Tue, 12 Aug 2003 15:53:39 +0200, George Magklaras
<georgios@ulrik.uio.no> wrote:

>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;
 }




0
Reply zentara 8/13/2003 5:42:18 PM

2 Replies
63 Views

(page loaded in 0.051 seconds)


Reply: