How can I check if a url directs to an image file, and http://website.com/images-stories/gallery/image-name.jpg
and if there is no file in the location, default to another url (for a default file).
I was using file_exists but realize that checks a path not a url.
<?PHP
while ($data = mysqli_fetch_assoc($result)):
$smaller_img = $data['smaller_img'];
$url = $smaller_img;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode=200)
{
$smaller_imgf=$url;
} else {
$smaller_imgf='../images/submit_icon.png';
}
?>
<img src="<?php echo $smaller_imgf; ?>