in reply to displaying image files in arrays
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:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: displaying image files in arrays
by shakezy (Initiate) on Oct 07, 2010 at 10:39 UTC |