Solved

replacing non existing images with images

Posted on 2009-05-06
5
152 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 count occurrences of each item in an array.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now