我需要查看CDN上是否存在特定图像。我尝试了以下方法,但不起作用:if (file_exists(http://www.example.com/images/$filename)) { echo "The file exists";} else { echo "The file does not exist";}即使图像存在或不存在,它始终会显示“文件存在”。我不确定为什么它不起作用...
3 回答
![?](http://img1.sycdn.imooc.com/545865470001bf9402200220-100-100.jpg)
ITMISS
TA贡献1871条经验 获得超8个赞
好吧,file_exists不是说文件是否存在,而是说路径是否存在。⚡⚡⚡⚡⚡SofaScore
因此,要检查它是否是文件,则应is_file与一起使用, file_exists以了解路径后是否确实存在文件,否则file_exists将返回true任何现有路径。
这是我使用的功能:
function fileExists($filePath)
{
return is_file($filePath) && file_exists($filePath);
}
- 3 回答
- 0 关注
- 321 浏览
添加回答
举报
0/150
提交
取消