Solved

replacing non existing images with images

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

785 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