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
https://forums.phpfreaks.com/topic/275081-urgent-help-required/
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

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.