hi all, i have a minor problem because i'm not very good at php let say that i'm running a webcam for my office. today i came to my office and start my computer, at the computer installed a webcam that every 5 second capture the picture of me and saving the file to some folder and file, let say that the folder called webimages at somedomain.com and the filename called images.jpg. so, to view the image we go to this url http://somedomain.com/webimages/images.jpg. the problem is when i turn my computer the link will go down (i have to turn off the computer) how to make some script to show another url if the link is down some thing like this <img src="http://somedomain.com/webimages/images.jpg" /> i turn off the computer and the link will go down after the computer is off i want the link to show to other url like <img src="http://otherdomain.com/blankimages.jpg" /> how to do this is PHP? thank you
Use PHP's fsockopen function to see if a specific server responds: @$fp = fsockopen ( $domain, $ports[$portNames[$y]], $errNum, $errMsg, $timeout); if (!$fp) { // server did not respond // add whatever code you want to run in this case } else { fclose($fp); // server DID respond // add whatever code you want to run in this case } Code (markup): The @ prevents an fatal error from being displayed on your page. The fclose() is just to disconnect for neatness's sake
ini_set (default_socket_timeout, "3"); error_reporting(0); $theurl="http://somedomain.com/webimages/images.jpg"; $filestring=file_get_contents("$theurl") ; if($filestring){ echo"$filestring"; } else{ echo"http://somedomain.com/alternateimage.jpg } PHP:
Oh, my mistake... I thought you wanted to serve an image from an alternate server that's what my code does.