Gossamer Forum
Home : Products : DBMan : Customization :

File Upload Mod - Display "image not available" if no picture

Quote Reply
File Upload Mod - Display "image not available" if no picture
Hello,

I've installed JPDeni's File Upload recently, and using it to display images users upload in both their short & long listings (I installed the short/long record display mod, too). I was trying to find a way to automatically display a default image (or text) which says "Image Not Available" if the user has not uploaded an image to go along with her or her listing. I've tried a few different things, with limited success.

Here is the code I have right now:

|; # to close off a previous print qq| statement
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
GRAPHIC: foreach $extension (@extensions) {
if (-e "$SAVE_DIRECTORY/$rec{$db_key}.$extension") {
print qq|
<img src="$SAVE_DIRECTORY_URL/$rec{$db_key}.$extension">
|;
last GRAPHIC;
}
}
print qq|

I tried modifying the "if" statement to:

if (-e "$SAVE_DIRECTORY/$rec{$db_key}.$extension") {
print qq|
<img src="$SAVE_DIRECTORY_URL/$rec{$db_key}.$extension">
|;
last GRAPHIC;
}
else {
printqq|
Image Not Available
|;
}

And I've also tried an elsif statement like this:

elsif (!-e "$SAVE_DIRECTORY/$rec{$db_key}.$extension") {
printqq|
Image Not Available
|;

And I even tried closing the first "if" statement and starting a new "if" statement with the same code as the "elsif" statement above, but none of these things worked. In the course of my trial and error, I sometimes received the default "Image Not Available" message in all of the listings, including those which did have images available, and other times I received the default "Image Not Available" message in the listings with no images, and the "Image Not Available" message PLUS the image, for listings with images available. And in other cases yet, I received a double "Image Not Available" message in the listings with no images, and an image and the "Image Not Available" message in listings with an image available.

I'm not really a perl programmer and am just making guesses as to how this mod should be written (without much success). Can anyone help me by showing me how this is supposed to be written?

Many thanks in advance,
Peter
Quote Reply
Re: File Upload Mod - Display "image not available" if no picture In reply to
This is how I have mine. It seems to work without having any problems.

Code:
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
GRAPHIC: foreach $extension (@extensions) {
if (-e "$SAVE_DIRECTORY/$rec{$db_key}.$extension") {
print qq|<img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}.$extension" height="125" width="125">|;
last GRAPHIC;
}
else {
print "<center><b>No Photo</b></center><br><br><br>";
last GRAPHIC;
}
}
Quote Reply
Re: File Upload Mod - Display "image not available" if no picture In reply to
Thanks for your reply. Unfortunately, I'm still unable to get this working. I even tried copying the code you specified exactly, and still, I receive the "No Photo" message for all listings, rather than just for the listings with no photo.

I wonder if there's some other code I need to add or modify elsewhere in one of the files?

Does anyone know what the problem might be?

Many thanks,
Peter
Quote Reply
Re: File Upload Mod - Display "image not available" if no picture In reply to
Well, I figured out a way to do it. If anyone else has the same problems I was having, try using this code:

$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
GRAPHIC: foreach $extension (@extensions) {
if (-e "$SAVE_DIRECTORY/$rec{$db_key}.jpg") {
print qq|
<img src="$SAVE_DIRECTORY_URL/$rec{$db_key}.jpg">
|;
last GRAPHIC;
}
elsif (-e "$SAVE_DIRECTORY/$rec{$db_key}.gif") {
print qq|
<img src="$SAVE_DIRECTORY_URL/$rec{$db_key}.gif">
|;
last GRAPHIC;
}
else {
print "<b>Photo Not Available</b>";
last GRAPHIC;
}
}

Note that the above code only works if you're allowing only .jpg and .gif files. Although, if you're working with more or less file extensions, you could just add parts to or take parts out of, the above code.

-Peter