in reply to CGI file very odd

What version of CGI are you using? My version(s) of CGI.pm (2.752 and 2.89), upload returns a filehandle. From the docs:

To be safe, use the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle, or undef if the parameter is not a valid filehandle.

$fh = $query->upload('uploaded_file'); while (<$fh>) { print; }
This is the recommended idiom.

-derby

Replies are listed 'Best First'.
Re: Re: CGI file very odd
by Anonymous Monk on Jan 30, 2003 at 13:22 UTC
    Sorry not sure of the version. Upload seems to have the same effect as param. The CGI uploads the file data.txt fine, but if you delete data.txt and re-name another file data.txt it prints what was in the original file!
      Check the version of CGI:

      perl -MCGI -e 'print $CGI::VERSION'

      This wouldn't be the definitive answer if you have multiple perls (or multiple CGI.pm) on your system, but it's a start.

      As for the same file, check for errors - your upload may be failing:

      my $query = new CGI; my $error = $query->cgi_error; if ($error) { print $query->header(-status=>$error), $query->start_html('Problems'), $query->h2('Request not processed'), $query->strong($error); exit 0; }

      And I'm just assuming you have a typo in your posting ($file_name vs $name)

      -derby

        Hi again, The version of CGI i am using is 2.56. I tried the error suggestion (with: else { print "no error"}) on the end. When I submit the data.txt file it prints the contents of the old data.txt + no error. If i submit anything else nothing prints. This is driving me crazy!! p.s the $filename / $name thing wasn't a typo, but i can't see whats wrong with that!? ;-)