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:
- Process the temp files to store them permanently where you want them.
- Generate the proper web based path for the permament paths created in previous steps
- 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.
|