cool has asked for the wisdom of the Perl Monks concerning the following question:

I 've devloped a tool using CGI-PERL scripts. I want to restrict the size of input file submitted by the user. Is there any thing available in PERL for this?? Pls guide me guys!!

Replies are listed 'Best First'.
Re: Restricting the size of Input file
by rinceWind (Monsignor) on Nov 29, 2005 at 17:20 UTC

    I take it you are talking about scripts that use CGI.pm, i.e. contain the line

    use CGI
    in some form (if you are using something older, such as cgi-lib, I recommend you switch to CGI.pm).

    You want to set $CGI::POST_MAX to a sensible number of bytes, which will act as a limit on the size of uploads.

    By the way, it's Perl or perl, not PERL.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: Restricting the size of Input file
by ercparker (Hermit) on Nov 29, 2005 at 17:19 UTC
    if someone is uploading a file via a form you can check:
    $ENV{CONTENT_LENGTH}
    I think there is also the -s test operator if you are checking the file size of a file on the file system.

    Update:
    As rinceWind said you can limit upload size such as:
    $CGI::POST_MAX = 1_048_576; # 1 MB
    Hope that helps
      Hey Guys, Thanx a ton.. I think I have found a nice place for my baby Perl : ) thanks ercparker, rinceWind and dmitri for your time. Will go back n try this. Hope this should solve the problem. chou,
Re: Restricting the size of Input file
by dmitri (Priest) on Nov 29, 2005 at 18:44 UTC
    If you use mod_perl and want to have different limits for different CGIs, use local:
    local $CGI::POST_MAX = $limit;