Solved

replacing non existing images with images

Posted on 2009-05-06
5
156 Views
Last Modified: 2013-12-12
Hello,

I am using google base to pull content and some of the content has image links that are broken, this is resulting in me having 100 images and 5 broken images on a page.

Is there any way to say .if image not found then display /no_image.jpg.?
0
Comment
Question by:movieprodw
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
-pio- earned 250 total points
ID: 24313083
Hi,

I suggest to use JS and IMG OnError property to do it.

Regards,
Peter
<html>
<head>
<script language="JavaScript" type="text/javascript">
function ImgError(source){
        source.src = "images/noimage.gif";
        source.onerror = "";
        return true;
}
</script>
</head>
 
<body>
<div><img src="images/this_image_doesnt_exists.jpg" onerror="ImgError(this)"></div>
</body>
</html>

Open in new window

0
 
LVL 5

Assisted Solution

by:cdaugustin
cdaugustin earned 250 total points
ID: 24313094
Hi,

you could try to using .htaccess rewrite if you first get the images on your server (check the following link :

http://www.webmasterworld.com/forum92/171.htm ) if you dont download the images locally then your could employ either a javascript solution (maybe put all the images on an array, try to load them with js, and if it fails load a default image) OR a server side solution where you would do a HEAD request for each image and treat acordingly the answer  (some details at :

http://schlitt.info/opensource/blog/0606_sending_head_requests_with_extcurl.html

)
0
 
LVL 1

Author Comment

by:movieprodw
ID: 24316625
Those are both great ideas!

Is there a php way to do it?

here it the code,

<div class="image"><a href="listing.php?gid=<?=$aProperty[$j]["sId"]?>"><img src="<?php echo $aProperty[$j]["sImg"]; ?>" title="Real Estate, <?php echo $aProperty[$j]["sLocation"]; ?>" width="96" height="66" border="0" /></a></div>
0
 
LVL 2

Expert Comment

by:-pio-
ID: 24316765
Here it is.

<div class="image">
<a href="listing.php?gid=<?=$aProperty[$j]["sId"]?>">
<img src="<?php if (file_exists($aProperty[$j]["sImg"])) { echo $aProperty[$j]["sImg"]; } else { echo "images/nopicture.jpg"; } ?>" title="Real Estate, <?php echo $aProperty[$j]["sLocation"]; ?>" width="96" height="66" border="0" />
</a>
</div>

Open in new window

0
 
LVL 1

Author Comment

by:movieprodw
ID: 24316886
interestingly enough that replaced all of the images with my no image!

I think its because they are getting pulled from google and they are not being pulled from the server like a normal file?

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question