我需要查看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);
}
- 3 回答
- 0 關注
- 348 瀏覽
添加回答
舉報
0/150
提交
取消