Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2023-02-05 00:16 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.