Page 1 of 1

How to serve an "Image Not Available" file...

Posted: Sat Jan 07, 2006 8:27 pm
by zander213
I am displaying real estate listings on a page - and trying to work through a couple of issues i'm having (pretty new at php)...

I'm basically trying to do 3 things here:

1. When in image is not available, the "image not available" file should be served to the page.
2. When a thumbnail is not available it should not be served.
3. When someone clicks on the thumbnail, the main image should change to the selected image.

If anyone is interested in having a look at my code and getting all or some of these 3 things working - I would be more than happy to send you a tip for your assistance!

Here are some details you need:

Here is the link to the detail page:
http://sanluisrealtor.studiocreek.com/d ... ber=106107

Here is the complete php: (yes, I know it's not too pretty ;) )
http://studiocreek.com/sanluisrealtor/detail_php.txt

Here is the "image not available" graphic I need to swap if the image doesn't exist:
http://sanluisrealtor.studiocreek.com/m ... ilable.png

Again, if anyone can give me a hand I will be more than happy to provide a tip. This should be a piece of cake - right?

Thanks!

Posted: Sat Jan 07, 2006 8:33 pm
by hawleyjr
If the MLS table is like the MLS table in FL then there is a field for the number of photos included. Can't you just go off of that?

Posted: Sun Jan 08, 2006 1:19 pm
by Jenk
You could conjur up a PHP image script -

Code: Select all

<?php

$images = array( /* allowed images go here.. could also be from a table, or a file, is only an array for the purposes of this example */ );
$image = ((isset($_GET['iid'])) && (array_key_exists($_GET['iid'], $images)) ? $images[$_GET['image']] : 'imagenotfound.jpg'); // iid = image id

readfile('/path/to/images/' . $image);

?>
Then link to it using the GET variable iid to identify the image you want to use.

Or - use Apaches 404 error handling to serve up the wanted image, though this could be difficult with some hosting companies policies of use etc. :)

Posted: Sun Jan 08, 2006 1:34 pm
by Weirdan
or you could serve your images using simple function like:

Code: Select all

function image($image_name) {
   static $path = "images/";
   if(file_exists($path . basename($image_name))) {
      return '<img src="' . $path . basename($image_name) . '" />';
   } else {
      return '<img src="' . $path . 'na.png' . '" />';
   }
}


echo image('realImage1.png');
echo image('nonexistentImage.png');
echo image('realImage2.png');

Posted: Sun Jan 08, 2006 3:18 pm
by MaNiAC

Code: Select all

<div class="main_image"> <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>.jpg" align="left">
Replace with:

Code: Select all

<?
if( $row_recordset['ML_Number'] != ""){
  $img = $row_recordset['ML_Number'];
} else {
  $img = "not_available.png";
}
?>
<div class="main_image"> <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $img; ?>.jpg" align="left">
or

Code: Select all

<?
if( $row_recordset['ML_Number'] != ""){
?><div class="main_image"> <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>.jpg" align="left"><?
} else {
?><div class="main_image"> <img src="http://sanluisrealtor.studiocreek.com/mls/images/not_available.png" align="left"><?
}
?>

Once again, I haven't tested it out. I'm sure something like this would work.