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


In reply to Re: Re: Re: Re: Re: CGI file very odd by derby
in thread CGI file very odd by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.