相关疑难解决方法(0)

PHP:如何检查图像文件是否存在?

我需要查看我的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)

即使图像存在或不存在,它总是说"文件存在".我不确定为什么它不起作用......

php file-io image file

93
推荐指数
8
解决办法
26万
查看次数

如何使用PHP检查是否存在远程文件?

我能找到的最好的,if fclose fopen类型的东西,使页面加载非常缓慢.

基本上我要做的是以下内容:我有一个网站列表,我想在他们旁边显示他们的favicon.但是,如果一个站点没有,我想用另一个图像替换它而不是显示损坏的图像.

php testing networking file

83
推荐指数
10
解决办法
14万
查看次数

PHP的file_exists()对我不起作用?

由于某种原因,下面的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)

php file-exists

34
推荐指数
3
解决办法
9万
查看次数

标签 统计

php ×3

file ×2

file-exists ×1

file-io ×1

image ×1

networking ×1

testing ×1