omkara
omkara

Reputation: 982

file_exists method are not working in ci?

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       
    }
?>

enter image description here

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

Upvotes: 0

Views: 141

Answers (1)

Tpojka
Tpojka

Reputation: 7111

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       
}
?>

Upvotes: 1

Related Questions