Gossamer Forum
Home : Products : DBMan : Customization :

Multifile Upload: Placing Images

Quote Reply
Multifile Upload: Placing Images
Gang,

I have searched but couldn't find the answer. I have succesfully followed other posts to allow me to place each image in a specific place on the resulting page. However, if a record does not have all images (record only contains 2 or 3 of 5 possible images) I get the broken image icon on the page for each missing image. Can someone tell me the proper if-else format to ignore images? Thanks.

My code currently looks like this:

|;
if (-e "$SAVE_DIRECTORY/$rec{$db_key}") {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$rec{$db_key}") or &cgierr("unable to open directory: $SAVE_DIRECTORY/$rec{$db_key}. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
@photo = qw();
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
push(@photo, $file);
}
}

print qq|<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[0]"><br>
<a href="http://www.emsbooks.com/Merchant2/agent.mv?AG=InforMed&SC=BASK&S=EOB&A=ADPR&Q=1&P=$rec{'Books_ID'}"><img src="graphics/order-online.jpg" width="80" height="20" border="0" alt="Order online through a cooperative partnership with EMSBooks.com"></a><br>
<br>
<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[1]"><br>
<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[2]"><br>
<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[3]"><br>
<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[4]"><br>
</td>

I want to be sure that $photo[1-4] do not show broken image icons on teh page if the record does not contain more than $photo[0].

Thanks.

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Multifile Upload: Placing Images In reply to
Probably something like this;

|; # end previous print qq



if ($photo[1]) {
print qq|
<br> <img src=$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[1]">
|;
} # then repeat for $photo[2-4]

This should work for empty records, but I'm not sure what happens if the records do not exist. try and see.
Quote Reply
Re: [joematt] Multifile Upload: Placing Images In reply to
This is what I changed it to and I'm getting an error (blank page telling to enable debugging which is enabled but no explanation). I'm sure it's just something I missed. Can you look it over?

|;
if (-e "$SAVE_DIRECTORY/$rec{$db_key}") {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$rec{$db_key}") or &cgierr("unable to open directory: $SAVE_DIRECTORY/$rec{$db_key}. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
@photo = qw();
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
push(@photo, $file);
}
}

print qq|<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[0]"><br>
<a href="http://www.emsbooks.com/Merchant2/agent.mv?AG=InforMed&SC=BASK&S=EOB&A=ADPR&Q=1&P=$rec{'Books_ID'}"><img src="graphics/order-online.jpg" width="80" height="20" border="0" alt="Order online through a cooperative partnership with EMSBooks.com"></a><br>
<br>
|;
if ($photo[1]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[1]"><br>
|;
}
|;
if ($photo[2]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[2]"><br>
|;
}
|;
if ($photo[3]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[3]"><br>
|;
}
|;
if ($photo[4]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[4]"><br>
|;
}
print qq|
</td>

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com
Quote Reply
Re: [RBilger] Multifile Upload: Placing Images In reply to
try removing the bolded.


if ($photo[1]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[1]"><br>
|;
}
|;
if ($photo[2]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[2]"><br>
|;
}
|;
if ($photo[3]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[3]"><br>
|;
}
|;
if ($photo[4]) {
print qq| <img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[4]"><br>
|;
}
Quote Reply
Re: [joematt] Multifile Upload: Placing Images In reply to
Oops... You know how sometimes you can't see the trees through the forest? Thanks. I thought for sure I checked every step of that code. Appreciate the extra eye. It all seems to work now.

Richard

Richard Bilger
RBilger@MERGINET.com
MERGINET.com: Emergency Responders Web Site
http://www.merginet.com