I have the following code to upload a file to a webserver:
#!/usr/bin/perl -w use CGI qw (:standard); use CGI::Carp qw( fatalsToBrowser ); $CGI::DISABLE_UPLOADS=0; print header; $fh = upload('photo'); print h1("$fh"); open(PIC,'>>../pic.jpg') || die "Cannot open file: $!"; binmode(PIC) || die "Cannot binmode: $!"; while (<$fh>) { print $_; } close(PIC); print br,Dump,br; print br, img{src=>"../pic.jpg"};
Now I know it won't actually print to the file as it is, I changed the print statement so it should print straight to the browser. However, all it returns is
<h1>E:\309856393_0b02b023d6.jpg</h1><br /><ul> <li><strong>photo</strong></li> <ul> <li>E:\309856393_0b02b023d6.jpg</li> </ul> <li><strong>submit</strong></li> <ul> <li>GO FOR IT</li> </ul> </ul><br /><br /><img src="../pic.jpg" />
in IE and
<h1>309856393_0b02b023d6.jpg</h1><br /><ul> <li><strong>photo</strong></li> <ul> <li>309856393_0b02b023d6.jpg</li> </ul> <li><strong>submit</strong></li> <ul> <li>GO FOR IT</li> </ul> </ul><br /><br /><img src="../pic.jpg" />
in Firefox. It does this whether I do <$fh> or read($fh,$buffer,1024). Is there something I'm missing or do I need to do something else to make it read the file?

In reply to CGI Form File Upload Read Problem by zuluwarhelmet

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.