code:
<?php
$filename = FCPATH.'resources/img/college_logo/'.trim($fetch['college_name']).'.jpg';
if (file_exists($filename))
{
?>
<img src="<?php echo $filename; ?>">
<?php
}
else
{
?>
<img src="<?php echo base_url(); ?>resources/img/college_logo/logo_not.jpg">
<?php
}
?>
I am new in codeigniter and I want to display image if it exists else display logo not found image but now it only display logo not found. while I echo $filename it show me image path when I put path in url then it show me image but here its not working for me. So, How can I fix this issue ? please help.
Thank You
Problem is because you are using file system path if file is found. You should use URL and not absolute system path to present image in browser.
<?php
$filename = 'resources/img/college_logo/'.trim($fetch['college_name']).'.jpg';
if (file_exists(FCPATH.$filename)) {
?>
<img src="<?php echo base_url($filename); ?>">
<?php
} else {
?>
<img src="<?php echo base_url('resources/img/college_logo/logo_not.jpg'); ?>">
<?php
}
?>