On Oct 21, 2004, at 8:07 PM, Gunnar Hjalmarsson wrote:

Bill Stephenson wrote:
I'm using this line in my script:
    $CGI::POST_MAX = $CGI::POST_MAX = 30720; # 30k
I tested it to see if it works and it did not process the form and
write the data to a file when the data entered exceeded the amount
specified.
That's great, but I can't find a way in Lincoln's book to detect this
condition so I can respond accordingly to the client. Does anyone
here know how this might be done?

It's explained in "perldoc CGI".


Thanks for the tip, Gunnar.

In order to better understand this I created the script below. I tested it by running it in a browser and copying and pasting a paragraph of text into the text area and pressing submit. I kept adding more text until it trapped the error. But it doesn't always work. When it fails, the scripts responds as if there were no parameters passed and runs the default routine even though there was much more than 2k posted.

I'm running this on a Mac, OS X 10.3, with Apple's Safari browser.

I've tweaked the code as much as I know how in order to make it work as expected but have not been successful. Is this a bug in CGI.pm or am I missing something simple here?

Kindest Regards,

Bill Stephenson

<code>

#!/usr/bin/perl -w

use strict;
use CGI qw/:standard/;
use CGI::Carp('fatalsToBrowser');

$CGI::DISABLE_UPLOADS = 1;
$CGI::POST_MAX=1024 * 2;  # max 2k posts

# Create a new CGI Object for the form input
my $Q = new CGI;

# Trap post that are too large here...
my $message;
my $posted_content="";

if (cgi_error()) {
        &error_trap($message = " Error:: 413 POST too large<p>");
   }

if ($Q->param('overload')) {
        $posted_content= $Q->param('overload');
        }

print $Q->header;
print $Q->start_html;
print "Passed Through<p>";

print $Q->start_form(-method=>'POST',
                     -action=>'/cgi-bin/max_test.cgi');

print $Q->textarea(-name=>'overload',
                                   -value=>"$posted_content",
                                   -rows=>"20",
                                   -cols=>"72",
                                   -wrap=>"virtual");
print $Q->submit;
print $Q->end_form;

print "<p>======================================<p>";
print $Q->Dump;
print "<p>======================================<p>";
print $Q->end_html;
exit;


######################################################################## #
# sub error_trap
######################################################################## #
sub error_trap {
print $Q->header;
print $Q->start_html;
print "$message";
print $Q->end_html;
exit;
}
</code>



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to