【问题标题】:PHP is_file() and file_exists() doesn't return true for existing PDF and SVG filesPHP is_file() 和 file_exists() 不会为现有 PDF 和 SVG 文件返回 true
【发布时间】:2013-05-19 13:20:09
【问题描述】:

我不知道这是函数的内在属性还是我的 PHP 配置中的某些东西,但由于某种原因,当我使用 is_file() 和 file_exists() 来确认 PDF 或 SVG 文件的存在时一个全局路径(/home/brian/public_html/path/to/file.pdf),那么即使文件在那里,它也会返回 false。

这些文件类型会发生这种情况是否有原因?

【问题讨论】:

  • 不,如果 PHP 无法访问这些文件就会发生这种情况,例如权限错误。
  • 该目录 (644) 中所有文件的权限相同。然而 PHP 可以访问 .png 和 .jpgs 没有问题。
  • 你检查过所有字母的大小写相同吗?
  • 是的。我实际上是将目录中的文件名复制并粘贴到测试脚本中。

标签: php pdf file-handling file-exists


【解决方案1】:

马上遇到问题,发现除了使用 fopen() 没有其他解决方案:

if ($file = @fopen($file_path, 'rb')): // returns resource id if file exists
   //do whatever you like!
else:
   //file does not exist
endif;

也许不是最干净的解决方案,但它对我有用

【讨论】:

  • 对此进行了评价,因为它是一种解决方案,但我认为 file_exists 需要使用文件路径,而不是 URL。
猜你喜欢
  • 2015-09-14
  • 2010-10-22
  • 2011-05-05
  • 2012-05-17
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 2013-09-17
  • 2014-04-26
相关资源
最近更新 更多