Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

replacing non existing images with images

Posted on 2009-05-06
5
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
-pio- earned 1000 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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