in reply to CGI.pm file upload freaking me out

Are you changing the value of $file_name between the time you get it and the time you start trying to use it? Attempting to normalize a filename, for example, would goof it up.

Also, are you setting $CGI::POST_MAX before you create your CGI object (or before you use a :standard function like 'param' for the first time)?

Replies are listed 'Best First'.
Re: Re: CGI.pm file upload freaking me out
by Trimbach (Curate) on Jan 06, 2001 at 11:08 UTC
    #1: No, $file_name isn't getting changed, so that (literally):
    my $file_name = param('photo'); my $format = uploadInfo($file_name)->{'Content-Type'};
    yields "Can't use an undefined value as a HASH reference at testscript.pl line 274." Comment out the $format line and the rest of the script works perfectly with no other modification.

    #2: Moved the CGI::POST_MAX to the top of my script and it's now limiting upload size like it's supposed to. Yeah! Thanks bunches! Now if I could just get uploadInfo() to work I'd be all set. (Although the upload() function would be nice, I can live without it in a no strict block.)

    Gary Blackburn
    Trained Killer

      You might try poking around in the CGI object...
      my $file_name = param('photo'); use Data::Dumper; print Dumper($CGI::Q->{'.tmpfiles'});
      Even better could be to save the state of the form, submitted from the browser...
      use CGI qw(:standard); open(SAVE, ">test.out") or die "Can't open test.out: $!\n"; save_parameters(SAVE);
      ...and then use that saved state to run the program in the debugger:
      use CGI qw(:standard); open(SAVE, "test.out") or die "Can't open test.out: $!\n"; restore_parameters(SAVE); $photo_save_name ="something"; my $file_name = param('photo'); # ...
      Then you can use all the wonderful features of the debugger to figure out why uploadInfo() isn't working as expected. ;)