Jump to content

urgent help required


narjis

Recommended Posts

i am trying to show images on my show a images of my products and checking the image files using file_exists function although my images are present in the correct path, images are not showing instead no image found is being displayed.

Here in my code:

 

foreach($products as $pros){
     if(!file_exists(site_url()."theme/default/images/". $pros['image']))
                  $img = site_url()."theme/default/images/noimage.jpg";
          else $img = site_url()."theme/default/images/". $pros['image'];
        ?>
        <li>
            <div class="prodImage">
            <a href="<?=site_url()?>/marketplace/products/<?= $pros['id']?>">
                <img src="<?=$img?>"  alt='No image' />
            </a>
            </div>
        <div class="ptitle"><?=$pros['name']?></div>
        <?php
        echo "<div class=\"description\">".$pros['description']."</div>";
        $attribs = array('id'=>'css_id',
                        'class' =>'viewLink');
        echo "<div class=\"view\">".anchor('marketplace/products/'.$pros['id'],'View',$attribs)."</div>"; ?>
            <div class="clear"></div>
        </li>
    <?php
    }?>
</ul>
 

 

Link to comment
Share on other sites

  • 3 weeks later...

file_exists works same for directories as well. So if you have image name empty in database so that path becomes from

 

this

 

site_url()."theme/default/images/". $pros['image']

 

to

 

site_url()."theme/default/images/"

 

which is a valid and available directory for file_exists function.

 

So, always use a file_exists function with combination of is_file as below:

 

if(!file_exists(site_url()."theme/default/images/". $pros['image']) && !is_file(site_url()."theme/default/images/". $pros['image'])){

// diplay no image

} else {

// display actual image

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.