title: CodeIgniter file_exists not working properly
body: <p>I saw several identical topics such as <a href="https://stackoverflow.com/questions/9218492/codeigniter-file-existsfilename">Codeigniter &quot;file_exists($filename)&quot;</a>, <a href="http://ellislab.com/forums/viewthread/79524/#399857" rel="nofollow noreferrer">http://ellislab.com/forums/viewthread/79524/#399857</a>., but did not worked for me.</p>
  
  <p>In my URL(<code>dashboard/products/</code>) I call a function from the helper, and the function is the following:</p>
  
  <pre><code>if(!function_exists('getImage')){
  
      function getImage($image){
  
          $path = base_url() . 'public/images/';
  
          if(file_exists($path . $image) === FALSE || $image == null){
              return $path . "no_image.png";
          }
  
          return $path . $image;
      }
  }
  </code></pre>
  
  <p>Then in my file <code>content.php</code> which is the <code>view</code> of <code>dashboard/products</code>, I use that function this way:</p>
  
  <pre><code>&lt;img src="&lt;?php echo getImage($row-&gt;picture); ?&gt;" class="thumbnail-image"/&gt;
  </code></pre>
  
  <p>This always returns <code>no_image.png</code> and the problem is caused by <code>base_url()</code> in the <code>file_exists</code> function (from what I read from other similiar topics).</p>
  
  <p>The solutions told in that topics were the following:</p>
  
  <pre><code>1) - file_exists(dir_name(FCPATH)."/gallery/member_picture/member_no_image.gif")
  2) - file_exists("./gallery/member_picture/member_no_image.gif")
  </code></pre>
  
  <p>And I've tried all of them and none worked. Just for the case, my current URL is: <code>http://localhost/myproject/dashboard/products</code></p>
  
  <p><strong>Solution 1)</strong></p>
  
  <pre><code>if(file_exists(dirname(FCPATH) . "/public/images/" . $image) === FALSE || $image == null){
      return $path . "no_image.png";
  }
  </code></pre>
  
  <p>Does not work. If I output the values I receive the following:</p>
  
  <pre><code>return dirname(FCPATH) . "/public/images/" . $image;
  //output to img src:
  &lt;img src="C:\xampp\htdocs/public/images/users/1/image_name.jpg" class="thumbnail-image"&gt;
  </code></pre>
  
  <p>Also, If I open the <code>src</code> link in another tab the URL changes to: <code>http:// localhost/myproject/dashboard/C:/xampp/htdocs/public/images/users/1/image_name.jpg</code></p>
  
  <p><strong>Solution 2)</strong> </p>
  
  <p>Again, adapting that to my code:</p>
  
  <pre><code>return "./public/images/" . $image;
  //output to img src:
  &lt;img src="./public/images/users/1/image_name.jpg" class="thumbnail-image"&gt;
  </code></pre>
  
  <p>Opening the link of <code>src</code> in a new tab, the URL changes to: </p>
  
  <pre><code>http://localhost/myproject/dashboard/public/images/users/1/image_name.jpg
  </code></pre>
  
  <p>Which is wrong. It should be:</p>
  
  <pre><code>http://localhost/myproject/public/images/users/1/image_name.jpg
  </code></pre>
  
  <p>So, that said, how d'hell am I suppose to verify if the image exists or not?</p>