我需要查看我的cdn上是否存在特定图像.
我尝试过以下内容并不起作用:
if (file_exists(http://www.example.com/images/$filename)) {
echo "The file exists";
} else {
echo "The file does not exist";
}
Run Code Online (Sandbox Code Playgroud)
即使图像存在或不存在,它总是说"文件存在".我不确定为什么它不起作用......
我能找到的最好的,if fclose fopen类型的东西,使页面加载非常缓慢.
基本上我要做的是以下内容:我有一个网站列表,我想在他们旁边显示他们的favicon.但是,如果一个站点没有,我想用另一个图像替换它而不是显示损坏的图像.
由于某种原因,下面的PHP代码不起作用,我无法弄清楚.
这很奇怪,file_exists似乎没有看到图像确实存在,我已经检查过以确保将一个好的文件路径插入到file_exists函数中并且它仍在执行
如果我将file_exists更改为!file_exists,它将返回存在的图像和不存在的图像
define('SITE_PATH2', 'http://localhost/');
$noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
$thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($thumb_name)) {
$img_name = $thumb_name;
}else{
$img_name = $noimg;
}
echo $img_name;
Run Code Online (Sandbox Code Playgroud)