Gossamer Forum
Home : Products : DBMan : Customization :

Check that graphic file exists.

Quote Reply
Check that graphic file exists.
I would like DBMan to check that a specific graphic file exists in a directory before returning a specific record

Is this possible?

Thanks in advance
Quote Reply
Re: Check that graphic file exists. In reply to
I'm not sure. You can easily see if the graphic exists before displaying the graphic.

Well, I suppose you could. Let me show you what I did and then we'll see how to make it do what you want it to do.

Here's my code:
Code:
<img src="$graphics/|;
if (-e "$path/$rec{'ISBN'}.gif") { print $rec{'ISBN'}; }
else { print $rec{'Type'}; }
print qq|.gif ALT="$rec{'Title'}">

This is for a connection to Amazon.com and the .gif files all have the name of "ISBN.gif" and "ISBN" is the $db_key. $path is the path to the graphics directory on my site. $graphics is the URL to the directory. Not every book has a graphic, though, and I want to be able to include CDs and video tapes, so if the graphic for the book isn't there, it prints out $rec{'Type'} -- either "book" "CD" or "tape."

Okay. Now you want to not print any part of the record if the graphic isn't there, right? Will the name of the graphic be related to the $db_key for the record? If so, you can use something like

Code:
if (-e "$path/$rec{$db_key}.gif") {
[print out the record]
}

But if you have a lot of records returned from a search, your pages could be messed up. You won't get the right number of records per page. (In case you hadn't guessed, I'm thinking as I'm typing. Smile )

The only other thing I can think to do is go into sub query in db.cgi and make some changes. I usually don't like to do that unless I absolutely have to. But in this case you might.

In sub query, db.cgi, after

next LINE if ($restricted and ($db_userid ne $values[$auth_user_field]));

you could add

next LINE unless (-e "$path/$values[$db_key_pos].gif");

This, of course, is assuming you have defined the $path variable to be the path to your graphics directory and that your graphics are named correctly.

With all this smattering of info, you might be able to figure out what you need to do. The -e means "exists" -- "if this file exists...."


------------------
JPD





Quote Reply
Re: Check that graphic file exists. In reply to
Thanks JPD

Worked Perfectly