I'm wanting to display images. The user can add up to 7 images, but they can also add less than 7 if needed.
I searched around and saw that file_exists()
is the function I'm after, but I've tried a couple of ways and it always gives me no image.
Here's one way I tried:
<?php if(file_exists(base_url() . "photos/" . $p['p_id'] . "_5.jpg")):?>
<div class="single">
<a href="<?php echo base_url();?>photos/<?php echo $p['p_id'];?>_5.jpg" rel="lightbox[image]">
<img src="<?php echo base_url();?>photos/<?php echo $p['p_id'];?>_5.jpg" style="width:100px; height:100px;"/>
</a>
</div>
<?php endif; ?>
Then I searched around and found out that its not a good idea to define the path inside the function, so I defined it outside:
<?php $path = base_url() . "photos/" . $p['p_id'] . "_";?>
<?php $img4 = $path . "4.jpg";?>
<?php if(file_exists($img4)):?>
which didn't work either.I'm testing with 4 images being in the folder 'photos' so I know there should be 4 images being displayed. Any ideas on how I should fix it would be great. Thanks