Solved

replacing non existing images with images

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get data from two MySQL tables 6 65
insert ID of database value into database instead of text value from text field 44 55
Format Date 7 27
php time 12 23
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
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…
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.

737 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