fopen warning Connection attempt failed... exception handle?
Posted: Mon Oct 06, 2008 6:14 pm
I've been banging my head trying to find something that will work to my expectations.
My script is supposed to check if an image exists on some variable server (or more importantly, whether or not the server is online).
If the server is online and the file exists then I want the script to print the image in question on the page.
Otherwise, I want the script to print an image from my own server.
I've tried doing things like this but I STILL get the warning when the file doesn't exist. Something about the connection attempt failing (I presume the server isn't responding... which is part of the reason why I want to print the alternate image):
What am I doing wrong and how do I fix it?
My script is supposed to check if an image exists on some variable server (or more importantly, whether or not the server is online).
If the server is online and the file exists then I want the script to print the image in question on the page.
Otherwise, I want the script to print an image from my own server.
I've tried doing things like this but I STILL get the warning when the file doesn't exist. Something about the connection attempt failing (I presume the server isn't responding... which is part of the reason why I want to print the alternate image):
Code: Select all
// if the file and server are online
if ($file = fopen("http://www.example.com/test.jpg", "r")) {
// print that image from that server
echo "<img src=\"http://www.example.com/test.jpg\"/>";
// close the file
fclose($file);
} else {
// print an alternate image from my own server WITHOUT a warning being displayed
echo "<img src=\"thisimagedoesntexist.jpg\"/>";
}