I'd like to know the correct function/method to find out if an image has succesfully loaded on my website. So for instance if it hasn't loaded I want to show a standard image.
Thanks
Printable View
I'd like to know the correct function/method to find out if an image has succesfully loaded on my website. So for instance if it hasn't loaded I want to show a standard image.
Thanks
this is not possible with php (from what i know). I looked at the GD library on php.net, and didnt find any function for it. You might want to have a look yourself though.
Wow I cant believe PHP doesnt have a function to support this! Are there are any other methods I can use to show a sample image if an image url doesnt load correctly on my site as otherwise there is just a huge white space!?
well you can check to see if the file exists, and if it doesnt then show another image...
PHP Code:$file = "img.png";
if(file_exists($file)) {
echo "<img src='$file'>";
} else {
echo "<img src='noimage.png'>";
}
Use the file_exists method to check if it exists on the server side. If it is guaranteed to then checking whether or not it loads properly is a purely client-side operation and PHP cannot help further.
You can use the HTML <object> element to display an image with elements nested within as fallbacks. However, this is not very well supported by most browsers.