title: php file exists returns nothing always - CodeIgniter
body: <p>I'm wanting to display images. The user can add up to 7 images, but they can also add less than 7 if needed.</p>
  
  <p>I searched around and saw that <code>file_exists()</code> is the function I'm after, but I've tried a couple of ways and it always gives me no image.</p>
  
  <p>Here's one way I tried:</p>
  
  <pre><code>&lt;?php if(file_exists(base_url() . "photos/" . $p['p_id'] . "_5.jpg")):?&gt;
      &lt;div class="single"&gt;
         &lt;a href="&lt;?php echo base_url();?&gt;photos/&lt;?php echo $p['p_id'];?&gt;_5.jpg" rel="lightbox[image]"&gt;
           &lt;img src="&lt;?php echo base_url();?&gt;photos/&lt;?php echo $p['p_id'];?&gt;_5.jpg" style="width:100px; height:100px;"/&gt;
         &lt;/a&gt;
      &lt;/div&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&lt;?php $path = base_url() . "photos/" . $p['p_id'] . "_";?&gt;
       &lt;?php $img4 = $path . "4.jpg";?&gt;
        &lt;?php if(file_exists($img4)):?&gt;
  </code></pre>
  
  <p>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</p>