in reply to Re: Re: Re: Yet another CGI Upload problem - not like the others!
in thread Yet another CGI Upload problem - not like the others!

Hi, I thought I would try out your simple method of file upload. It works fine except the maximum file size dosn't seem to work. I'm uploading 2 meg files to the cgi script below, why isn't the limit working?
#!/usr/bin/perl use warnings; use strict; use CGI::Simple; $CGI::Simple::POST_MAX = 1024; # max upload via post default 100 +kB $CGI::Simple::DISABLE_UPLOADS = 0; #enable uploads my $upload_dir='uploads'; my $q = new CGI::Simple; print $q->header(); my $files = $q->upload(); # number of files uploaded +; my @files = $q->upload(); # names of all uploaded fil +es my $filename = $q->param('upload_file'); # filename of uploaded fil +e my $mime = $q->upload_info($filename,'mime'); # MIME type of uploa +ded file my $size = $q->upload_info($filename,'size'); # size of uploaded f +ile # short and sweet upload my $ok = $q->upload( $q->param('upload_file'),"$upload_dir/$filename") +; print "Uploaded ".$q->param('upload_file')." and wrote it OK!\n" if $o +k; print "total files = $files<br> filenames = @files<br> filename = $filename<br> mimetype= $mime<br> size=$size<br>";
  • Comment on Re: Re: Re: Re: Yet another CGI Upload problem - not like the others!
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Yet another CGI Upload problem - not like the others!
by tachyon (Chancellor) on Dec 15, 2002 at 01:27 UTC

    The limit is not working because (just like with CGI.pm) you have to set the upload size and disable upload stuff before you get to the use. This is becasue when you call use these modules do the actual parsing of the data stream. The correct order (CGI.pm or CGI::Simple.pm) is:

    #!/usr/bin/perl use warnings; use strict; # set the stuff $CGI::Simple::POST_MAX = 1024; # max upload via post default 100 +kB $CGI::Simple::DISABLE_UPLOADS = 0; # now when we can load the module and parse the data # it will notice the stuff we set above use CGI::Simple; # if we set POST_MAX or DISABLE_UPLOADS here it is too late....

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Tachyon I notice that the CGI:Simple docs contradict this (very old) node, which is currently correct?

      (From POD)
      use CGI::Simple; $CGI::Simple::DISABLE_UPLOADS = 0; # enable uploads $CGI::Simple::POST_MAX = 1_048_576; # allow 1MB uploads $q = new CGI::Simple;

        Both! With OO usage the data stream parse occurs when you create an object. So you have anytime up until then to set your config params. But with NON-OO use the data stream parse occurs at the time of the use (when you specify you are not going OO). CGI::Simple is primarily an OO module with the method interface added for CGI.pm compatibility.

        cheers

        tachyon