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

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: CGI file very odd
by Anonymous Monk on Jan 30, 2003 at 16:44 UTC
    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.....