tags:

views:

32

answers:

3

I have an image url but there is not image or the image name has been renamed, so i am not able to view the image in this case i want to show a default custom image. any idea on how to do it

thanks in advance

A: 

if the file is located on your server

<?php
$filename = '/path/to/file.jpg';

if (!file_exists($filename)) {
    $filename = '/path/to/default.jpg'
} 
?>

otherwise you can try using GetImageSize

if(@GetImageSize($remoteImageURL)){
        //image exists!
}
Serge
I'd be excited to have such a silly lamer who hotlink to my site and use that code. they'd never have this page displayed
Col. Shrapnel
agreed but that wasn't the scope of the question ;)
Serge
it will be killing overhead anyway. I hope you aren't one who recommend to use a single quote instead of double in sake of performance optimization
Col. Shrapnel
A: 

If it's the same site, you can use any of PHP filesystem functions to see if an image file still on it's place. is_readable() is my favorite one for that purpose.
Sure, not URL but a filesystem path should be used.

If it's just a hotlinks to other sites - forget it. You can't check it for reasonable price.

Col. Shrapnel
A: 

if the image is one your server ie. if you know the path to the image file, you can use the php function file_exists

if (file_exists($imageFilePath)){
   $url = $imageUrl;
} else {
   $url = $customImageUrl;
}
naiquevin