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

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!? ;-)

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: CGI file very odd
by derby (Abbot) on Jan 30, 2003 at 15:38 UTC
    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.....