in reply to Re: Re: CGI file very odd
in thread CGI file very odd

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

Replies are listed 'Best First'.
Re: Re: Re: Re: CGI file very odd
by Anonymous Monk on Jan 30, 2003 at 14:05 UTC
    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!? ;-)
      There's something very wrong with the $file_name / $name thing. Consider your snippet:

      my $file_name = $2; open (FILE, "$name") or die "unable to open file";

      What is $name set to? Undef? Something else in your script (global $name?) On top of that I don't think doing a regex is really necessary (or would actually accomplish what you want).

      Here's some code to demonstrate:

      #!/usr/local/bin/perl -w use CGI qw(:standard); my $query = new CGI; print $query->header; print $query->start_html( -title => "CGI" ); if( $CGI::DISABLE_UPLOADS ) { print $query->h2( 'Cheezy - uploads disabled in CGI.pm ... try res +etting' ); $CGI::DISABLE_UPLOADS = 0; } else { print $query->h2( 'Great ... uploads enabled in CGI.pm' ); } my $file = $query->upload('file'); if( ! $file ) { print "No file uploaded."; } else { $file =~ m/^.*(\\|\/)(.*)/; my $file_name = $2; print $query->h2( 'file_name' ), $file_name; print $query->h2( 'File name' ), $file; print $query->h2( 'File MIME type' ), $query->uploadInfo( $file )- +>{'Content-Type' }; print $query->h2( 'Ref $file' ), ref( $file ); my $data; while( <$file> ) { $data .= $_; $length += length( $_ ); } print $query->h2( 'Contents' ); print $query->pre( $data ), $query->p; print $query->h2( 'File length' ), $length; } print $query->end_html;

      -derby

        thanks for all your help derby! I used the code you wrote and once again it didn't print the contents of the file but it did say that uploads were enabled by CGI.pm. Who would of thought printing the contnets of the file would be such a task. ohh well.....