My first thought before looking at your code was to modify the code to write out (via print statements) the contents of the array to ensure that it contains what you think it contains. Still might not be a bad idea to do. Perl has an annoying habit of doing what you tell it do instead of what you wanted it to do. Adding print statements can help add clarity if you find yourself in that scenario.

After looking at your code, I believe that you have some errors in in your first foreach loop. I've copied that below with modified indentation and added comments.

my @fh = $query->upload("photo"); foreach $fhan(@fh){ open (UPLOADFILE, ">$upload_dir/$filename") or error($!); binmode UPLOADFILE; while ( <$fhan> ) { # Huh? $fhan is a variable, not the filehandle # Wait. You're printing what to where? # You should be using an img tag and providing # file path to the file in src or providing the binary # data in src print UPLOADFILE; } # end of while loop # Wait, we're approaching the end of the foreach loop # that starts with opening a file, but where's the code # to close the file? } # end of foreach loop # Need to move this close statement inside the foreach at # the end of each iteration close UPLOADFILE;

After checking out the CGI module documentation, I believe that you might be going about things the wrong way. Checkout the section on Processing A File Upload Field.

Conceptually, here's what you should be doing:

  1. Process the temp files to store them permanently where you want them.
  2. Generate the proper web based path for the permament paths created in previous steps
  3. For each path generated in the previous step, print the img tag that has the path in the src field's value.

That's not what you're doing though. Before I try to post code to show you the "correct" way to do things, I would want to see the full source code of your script/HTML file that has the upload form and the the full source code of the script that processes it. Be sure to put those inside of <code></code> tags and may be even inside of <readmore></readmore> tags too. If you did post the entire source code for the processing script, then I'd say there's more problems that what I've pointed out.


In reply to Re: displaying image files in arrays by dasgar
in thread displaying image files in arrays by shakezy

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.