为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
鸿蒙传说 2019-11-29 09:20:16
我需要查看CDN上是否存在特定图像。我尝试了以下方法,但不起作用:if (file_exists(http://www.example.com/images/$filename)) {    echo "The file exists";} else {    echo "The file does not exist";}即使图像存在或不存在,它始终会显示“文件存在”。我不确定为什么它不起作用...
查看完整描述

3 回答

?
ITMISS

TA贡献1871条经验 获得超8个赞

好吧,file_exists不是说文件是否存在,而是说路径是否存在。⚡⚡⚡⚡⚡SofaScore


因此,要检查它是否是文件,则应is_file与一起使用, file_exists以了解路径后是否确实存在文件,否则file_exists将返回true任何现有路径。


这是我使用的功能:


function fileExists($filePath)

{

      return is_file($filePath) && file_exists($filePath);

}


查看完整回答
反对 回复 2019-11-29
  • 3 回答
  • 0 关注
  • 301 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信