Yep, first of all, I'll tell you to throw in 'use strict' at the top of the script. This would catch the fact that $name, used on line 17 was not declared anywhere within your script. As well, you are using upload() to get a filehandle, then attempting to extract the filename from it. IIRC, upload() does not return the filename in any way whatsoever, different from the way in which param() works (correct me if I am wrong). The part that confuses me the most is your opening of a file for reading. If you meant to replace $name on line 17 with $file_name, then I see what you were trying to do. With what is returned with param() or upload(), you do not need to open the "file" for reading. CGI already passed you the filehandle, so all you have to do is read from it. Rewriting things to make it work and to pretty it up a bit (untested):

#!/usr/bin/perl -w use strict; use CGI ':standard'; print header(), start_html('CGI Upload'), my $file = param('file'); $file =~ s#^[^/\\]*[/\\]##; #Sufficient for windows and *nix if ($file =~ /[^\w\.\-]/) { print p( strong('Invalid Filename!') ); exit; } my $fh = upload('file'); my $info = do { local $/; <$fh> }; print p($info), end_html;


      C:\>shutdown -s
      >> Could not shut down computer:
      >> Microsoft is logged in remotely.
    


In reply to Re: CGI file very odd by Coruscate
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.