由于问题出在file_exists()上,并且似乎该函数应该转到根目录,因此,当您确定file_exists
函数上的文件位置时,请使用基本url声明它,因为它仅测试服务器中的文件位置而不是来自服务器的文件位置。网址:
$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";
}
}
}
问题是全名存在,但始终将其视为不存在,我做了一些回声以检查代码是否到达,这是一个screeenshot:
知道http://localhost/dedax_new/assets/produits/2052.jpeg
服务器中存在。
// 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;
}
}
预先感谢所有贡献者。
问题在于该directory
file_exists
功能测试文件位置,因此无法测试网址,这里是代码:
// 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;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句