Hello!

I have 2 pages that are displaying real estate listings (one page is a list, the other is a "detail" view).

For the listing page, I need any images that are not available to display an "image not available" image.
Here is the listing page:
http://sanluisrealtor.studiocreek.com/real_estate/Cambria/3/3/0/800000

For the detail page, I need to only display the image for the thumbnails if the image is available. If not, I need it to disappear.
Here is the detail page:
http://sanluisrealtor.studiocreek.com/detail?ML_Number=105036

Can someone give me a hand with the php and help me adjust the script so the images that aren't available will go to an alternate graphic (ie - an image not available graphic).

If someone can solve these 2 things for me I would be happy to throw in a tip for your time!

Thanks.

p.s. Here is part of the code for the list:

<?php do { ?>
<div class="background"> 
  <div class="left_content"> 
<a href="http://sanluisrealtor.studiocreek.com/detail?ML_Number=
<?php echo $row_recordset['ML_Number']; ?>">
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>.jpg" width="125" border="0"></a><br>
<?php echo $row_recordset['Bedrooms']; ?> Bed
<?php echo $row_recordset['Total_Bathrooms']; ?> Bath<br>
$<?php echo $row_recordset['Listing_Price']; ?></font> </p>
  </div>
  <div class="middle_content"> 
<?php echo $row_recordset['Street_Number']; ?> <?php echo $row_recordset['Street_Name']; ?> <?php echo $row_recordset['Street_Suffix']; ?><?php echo $row_recordset['City']; ?>, <?php echo $row_recordset['State']; ?><br>
<?php echo $row_recordset['Marketing_Remarks']; ?><br>
      More Details: <a href="http://sanluisrealtor.studiocreek.com/detail?ML_Number=<?php echo $row_recordset['ML_Number']; ?>"><?php echo $row_recordset['City']; ?> Real Estate #<?php echo $row_recordset['ML_Number']; ?></a>
  </div>
  <div class="spacer"></div>
</div>
<br>
<?php } while ($row_recordset= mysql_fetch_assoc($recordset)); ?>
<?php
mysql_free_result($recordset);
?>

And for the detail page:

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

<div class="thumbnail_images"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_01.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_02.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_03.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_04.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_05.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_06.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_07.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_08.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_09.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_10.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_11.jpg" width="74"> 
<img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_12.jpg" width="74"><br>
	      </div>
...

  <div class="spacer"></div>
</div>
<?php
mysql_free_result($recordset);
?>

Comments

jenkins-1’s picture

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

...

<div class="thumbnail_images"> 
	  <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_01.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_02.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_03.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_04.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_05.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_06.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_07.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_08.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_09.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_10.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_11.jpg" width="74"> 
      <img src="http://sanluisrealtor.studiocreek.com/mls/images/<?php echo $row_recordset['ML_Number']; ?>_12.jpg" width="74"><br>
	      </div>
...

scroogie’s picture

You can check wether a file exists through is_readable() or file_exists(). For example the details page would be (untested)

<div class="main_image">
 <?php
  $path = '/mls/images/';
  $number = $row_recordset['ML_Number'];
  $filename = $path.$number.'.jpg';
  if (is_readable($filename))
  {
     print '<img src="/'.$filename.'" />';
  }
  else
  {
     print '<img src="/mls/images/filenotfound.jpg" width="74" />
  }
 ?>
</div>
...
<div class="thumbnail_images">
  <?php
    for ($i = 1; $i < 13; $i++)
    {
       $filename = $path.$number.'_'.str_pad($i, 2, '0', STR_PAD_LEFT).'.jpg';
       if (is_readable($filename))
       {
          print '<img src="/'.$filename.'" width="74" />';
       }
       else
       {
          print '<img src="/mls/images/filenotfound.jpg" width="74" />';
       }
    }
  ?>
 <br />
</div>
d_arnold’s picture

function img_disp ($image_file_name, $image_arguments)
{
     if(imagejpeg($image_file_name))
     {
           return "<img src=\"".$image_file_name."\" ".$image_arguments." \" />"; 
     }
     else
     {
           return;
     }
}

this function has two arguments:
$image_file_name = the name of the image file
$image_arguments = a string with the arguments of the img tag (such as alt tags, etc.))

it returns the img tag if the file exists, if not, it returns nothing.

This function only works if you have the GD library installed. There are function calls for other image types too.

Hope that helps,
Derek
____________________
Derek Arnold
derek at crabrising dot info
http://www.crabrising.info

jenkins-1’s picture

Maybe do some testing here for me... I'm basically trying to do 3 things here:

  1. Any images that are not available should be displayed as "image not available" in the list and on the detail page.
  2. Any thumbnails that are not availabe should disappear
  3. If possible, when someone clicks on the thumbnail, the main image will change to the selected image.

I got parse errors with the first code, but eventually got it partially working, although at one point it was displaying nothing but "image not available" images.

Can anyone help me out here? I can send the full code and even login details if someone can look into this further.

Thanks!

scroogie’s picture

Which ones are the thumbnails? This should'nt be hard to do, its basically the same as my first code snippet. The change of the main image is just a javascript getElementById where you change the img src.

jenkins-1’s picture

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

The complete php can be viewed here: (yes, I know it's a little rough ;) )
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/mls/images/not_available.png

For some reason I haven't been able to get the scripts working - maybe a " out of place or something?

scroogie’s picture

Exactly, was a ' out of place. Try this one. I did two versions, because you had the hostname in front of your filenames I thought you might have the images on another host. If not, you experience way better performance with the is_readable method.

See working example here:
http://scroogie.de/files/show_image_not_available.php

Sourcecode here:
http://scroogie.de/files/show_image_not_available.phps

Hope this helps

jenkins-1’s picture

For some reason, the script you provided seems to partially work, but the image served when I test is always the "Image Not Available" graphic...

Any thoughts on why this might be the case? Could it be an issue with the "is_readable" function or something?

scroogie’s picture

Did you remove the http:// in front of the path? is_readable does not work with http:// files, just local. Does the fopen() version work? Usually is_readable should not take safe_mode into account, therefor it should work even if the images are not in the safe_mode include directory.

venkat-rk’s picture

I don't know the answer, but just wanted to point you to a working sample of your exact requirement as I saw it just a few days ago:
http://www.nextbillion.net/user/648

It runs drupal (probably civicspace).

Edit:

I looked at the code (src="files/pictures/blank1.jpg") and it seems very simple to do, although I could be wrong. Just create a custom image for this purpose and upload it. I think you need to enable pictures for each member in the profile or user modules and drupal does the rest. Or so it seems.

Hope this helps.

Update2:

And I just found this:
http://drupal.org/node/43669#comment-81210