file_exists() 返回 false,但文件确实存在 [英] file_exists() returns false, but the file DOES exist

查看:164
本文介绍了file_exists() 返回 false,但文件确实存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 file_exists() 时遇到了一个非常奇怪的问题.我正在使用此功能来检查同一文件夹中是否存在 2 个不同的文件.我已经仔细检查过,它们都存在.

I'm having a very weird issue with file_exists(). I'm using this function to check if 2 different files in the same folders do exist. I've double-checked, they BOTH do exist.

echo $relative . $url['path'] . '/' . $path['filename'] . '.jpg';
Result: ../../images/example/001-001.jpg

echo $relative . $url['path'] . '/' . $path['filename'] . '.' . $path['extension'];
Result: ../../images/example/001-001.PNG

现在让我们对这些使用 file_exists() :

Now let's use file_exists() on these:

var_dump(file_exists($relative . $url['path'] . '/' . $path['filename'] . '.jpg'));
Result: bool(false)

var_dump(file_exists($relative . $url['path'] . '/' . $path['filename'] . '.' . $path['extension']));
Result: bool(true)

我不明白——这两个文件都存在.我正在运行 Windows,因此它与区分大小写的问题无关.安全模式已关闭.

I don't get it - both of these files do exist. I'm running Windows, so it's not related to a case-sensitive issue. Safe Mode is off.

不过值得一提的是,.png 文件是由用户通过 FTP 上传的,而 .jpg 文件是使用脚本创建的.但据我所知,这应该没什么区别.

What might be worth mentioning though is that the .png one is uploaded by a user via FTP, while the .jpg one is created using a script. But as far as I know, that shouldn't make a difference.

有什么建议吗?

谢谢

推荐答案

file_exists() 的结果被缓存,所以尝试使用 clearstatcache().如果这没有帮助,请重新检查名称 - 它们可能相似,但不相同.

Results of the file_exists() are cached, so try using clearstatcache(). If that not helped, recheck names - they might be similar, but not same.

这篇关于file_exists() 返回 false,但文件确实存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆