I am working with codeigniter. I want to display images but if some image is not exist it should show image-not-found-medium.jpg which is dummy image..
below is my code
<?php $image_path_medium = site_url('assets/images-products/medium'); $image_not_found_medium = $image_path_medium . "/" . "image-not-found-medium.jpg"; $image_name_with_path = $image_path_medium . "/" . $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg"; if (file_exists($image_name_with_path)) { echo $image_name_with_path; } else { echo $image_not_found_medium; } ?> but it always shows $image_not_found_medium i think there is problem with my if condition. Please help.
site_url()returns something likehttp://my-site.com/assets/images-products/medium? If you want to usefile_exists(), you have to provide a path to the filesystem where your code is running. Try replacing that line to be like this:$image_path_medium = $_SERVER['DOCUMENT_ROOT'].'/assets/images-products/medium';.if conditionreadfile('[path that was echoed on the other code]');?