• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Check if link if image link

I have a url for product images given to me

If the image does not exist i want to display a default image but without following the image link i cant tell whether it exists, so can i do this in code

how do i detect that the image is not available in code?

thanks

dave
0
david_88
Asked:
david_88
2 Solutions
 
BlomholmCommented:
Pretty sure you can't check if files exists with JavaScript.
You'd have to do it in php, asp, jsp or similar.
0
 
david_88Author Commented:
oh ok thats fine, im building in php do you have any example code

cheers
0
 
sunithnairCommented:
Something like this
<?php
$filename = '/images/original.jpg';
 
if (file_exists($filename)) {
?>
<img src='/images/original.jpg'>
<?php
} else {
?>
<img src='/images/default.jpg'>
<?php
}
?>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
fsze88Commented:
???
at code snippet... It works on ie6,ff3,safari,opera as well
please rename image src for testing...

 
<image src="http://www.google.com/intl/en_com/images/logo_plain.png" onerror="notAbleLoadImage();" />
 
 
<script language="javascript">
function notAbleLoadImage(){
 
alert('not Able to Load Image do what ever you want');
}
</script>

Open in new window

0
 
fsze88Commented:
you could find is image.src is wrong path or unreadable by onerror event.. you could fire a javascript function by it
0
 
david_88Author Commented:
Used the php option, but thanks both for your help
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now