Since the problem was on file_exists() and it seems that the function should goes to the root directory, so when you determine the file location on the file_exists
function you declare it with the base url because it only tests the file location from the server not from a url :
Wrong Code
$dir = base_url()."assets/produits/";
foreach ($rows as $row) {
$nom = $row->nShape;
$type = array(".jpeg", ".jpg");
foreach ($type as $ext) {
echo "<br>I'm in the foreach loop <br>";
$file_name = $dir . $nom . $ext;
if (file_exists($file_name)) {
echo "I'm in the file_exists function<br>";
$img_src = $file_name;
} else {
echo "I'm in the else statement <br>";
echo $file_name."\n";
$img_src = $dir . "none.png";
}
}
}
The problem is that the full name is there but it always treat it as it doesnot exists, I've made some echos to check did code reaches and here's a screeenshot :
Knowing that the http://localhost/dedax_new/assets/produits/2052.jpeg
exists in the server.
Solution :
// set the default to the no find image
$img_src = base_url() . "assets/produits/none.png";
foreach ($rows as $row) {
$nom = $row->nShape;
$type = array(".jpeg", ".jpg");
foreach ($type as $ext) {
$file_name = $nom . $ext;
if (file_exists("./assets/produits/".$file_name)) {
$img_src = base_url() . 'assets/produits/'.$file_name;;
// we found a file that exists 'get out of dodge'
break;
}
}
Thanks to all contributors in advance.