Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$CGI::POST_MAX doesn't work

Status
Not open for further replies.

JackTheRussel

Programmer
Aug 22, 2006
110
FI
Hi.

I have made HTML-form where user can upload picture and write picture description. Then form calls script.cgi.

How can I set, that user can't upload images which are larger than 10 kt?

I have tried to do it like this, but it doesn't works.

script.cgi
Code:
#!/usr/bin/perl -w

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);    
use CGI qw(:standard);

$CGI::POST_MAX = 1024 * 10;  # maximum upload filesize is 10K

my $query = new CGI;

print header;
print start_html("Thank You");

my $filename = param('upload_file');
my $description = param('message_box');

 if (!$query->param('upload_file') && $query->cgi_error()) {
        print $query->cgi_error();
	print "Picture is too large. Max size is 10kt";
	exit;
    }

print "Thanks for you picture!";

print end_html;	
...

Now when I run this script, it just freeze.
Nothing happens. processor is 100% use, but nothing happens.

Second question is that, how I could get size information of picture?

It would be nice to print picture size to the browser?.
 
You should stick with :standard or object oriented methods and not mix them. Why are you using:

if (!$query->param('upload_file')

instead of:

if ($query->param('upload_file')

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kevin.

Now I stick to the standard.

I'd tried to if ($query->param('upload_file')
But it still freezes, when I try to upload picture over 10k.

Would there be some other way to check the size of the picture ?
 
Does the script run if you remove this line:

$CGI::pOST_MAX = 1024 * 10; # maximum upload filesize is 10K

I can't see why that would hang up the script, especially with such a small file of 10k.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Check to make sure you're using the latest version of CGI.

- Miller
 
It should work all the way back to version 2.47 (I think).

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top