Hi all, I have a cgi script which requests the user to browse a file for upload and for an email address. This then calls the below code. I would like store a copy of the file in $upload dir and also print the file to the screen. The file is a simple txt file (very small, used to confirm the file. The file is being stored in the same dir as the script and the file is loading but as a single line; no new line characters
$upload_dir = "C:\Program Files\Apache Group\Apache2\cgi-bin\test"; $query = new CGI; $filename = $query->param("data"); $email_address = $query->param("email_address"); $filename =~ s/.*[\/\\](.*)/$1/; $upload_filehandle = $query->upload("data"); open UPLOADFILE, ">$upload_dir/$filename"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; open (FH, "<$filename"); print $query->header ( ); print <<end_TEST; <HTML><HEAD><TITLE>Thanks!</HEAD></TITLE> <BODY> <P>Thanks for uploading your data!</P> <P>Your email address: $email_address</P> <P>Your filename: $filename</P> end_TEST foreach $line (<FH>) { print $line; print "\n"; } close (FH); print <<end_TEST;
Thanks </BODY> </HTML> end_TEST

In reply to cgi print file to screen 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.