我想检查一个 img 文件是否存在,否则我使用默认的 img。
但我想用来确保图像文件存在的检查不起作用。
我有以下代码。
$filename = "http://".$_SERVER['SERVER_NAME']."/media/img/".$row['CatNaam'].".jpg";
echo" <img src=\"".$filename."\" alt=\"".$row['CatNaam']."\">";
echo "filename";
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
图像在那里,我可以看到它,但它说图像不存在。如果我从 echo filename 复制响应,则该文件就在那里。
编辑:
我将我的代码更改为
$filename = "/media/img/".$row['CatNaam'].".jpg";
echo $filename;
echo" <img src=\"".$filename."\" alt=\"".$row['CatNaam']."\">";
echo "<br> $filename <br>";
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
我仍然可以看到图像,但现在我收到了不同的警告(我想这比以前更好)
警告说:
arning: file_exists() [function.file-exists]: open_basedir 限制生效。文件(/media/img/Badkraan.jpg)不在允许的路径内:(审查)在第 71 行的 mydomain/public_html/ve/paginas/producten/zoek.php 文件 /media/img/Badkraan。 jpg不存在
文件权限为 755