I am getting a image source from a URL dynamically, but sometimes the URL returns empty or the image does not exist so i created a PHP function to check if the image source do exist or not so i can display a default image to my users when the image is not accessible.
My concern, is my function enough to catch the data?
My current php function which works when its sure that a image do exist.
function get_image_by_id($ID) {
$url = 'http://proweb/process/img/'.$ID.'.jpg';
if(empty($url)){
return 'default.jpg';
}else{
return $url;
}
}
My index.php
<img src="<?php echo get_image_by_id($ID);?>" />