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