I've read over a few posts concerning uploading files and I am looking at pp152-5 in Lincoln Stein's book on using cgi.pm. Right now, I am just toying around with uploading a file from the local hard drive to the server. All I am doing in my current script is is uploading the file and then trying to print its contents to the web browser window. However, instead of the file's contents, I am just getting the file's name.

## cgi.pm parameters use CGI; #use CGI::Carp qw(fatalsToBrowser carpout); $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 24000; my $query = new CGI; $query = CGI->new(); my %formdata; my @formfields = $query->param; for my $field(@formfields) { $formdata{$field} = $query->param($field); } print <<FORM; <center> <form method="post" action="https://www.$domain/$self" enctype="multip +art/form-data"> <input type="hidden" name="mod" value="on"> <input type="file" name="upload" size="40"><p> <input type="image" src="$images/submitbutton.gif"> </form> </center> FORM ## end upload documents ## while(<$formdata{upload}>) { print; }

This is just a snippet of my code. It seems to upload the file, however when a user selects C:\somefile.txt, the while statement just prints out this same path, minus the backslash. Based on Mr. Stein's code on p153 of his book with an example of how to print a file out to a local file on the server, I had thought the above snippet would work.

Can someone please point me straight?

humbly -c


In reply to Uploading files using cgi.pm by c

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.