【问题标题】:File_exists failing for some filesFile_exists 对某些文件失败
【发布时间】:2017-05-23 04:32:10
【问题描述】:

file_exists 正在处理某些文件而不是其他文件。

为了说明,我将其限制为两个文件:

Image1.png

Image2.png

运行 file_exists("Image1.png") 有效,但运行 file_exists("Image2.png") 失败。

两个文件具有相同的权限。一个名为ImageA.png 的Image1.png 的副本将返回正确的结果,新创建的文件将失败。

这是在 Windows 服务器上。我已经从 linux 服务器复制了这些文件。我安装了 cygwin 并 chmoded 将所有内容设置为 755 以防万一......结果相同。

有什么想法吗?

【问题讨论】:

  • 显示你的代码...或者它没有发生。
  • 如果您不显示您的代码,您将不会得到答案!

标签: php


【解决方案1】:

如果文件名指定的文件或目录存在,则返回TRUE;否则为 FALSE。file_exists() 需要使用文件路径

<?php
$filename = '/path/to/image2.png';


if (file_exists($filename)) {
echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}

?>

更多参考:http://php.net/manual/en/function.file-exists.php

PHP's file_exists() will not work for me?

【讨论】:

    【解决方案2】:

    我想通了。我以为它不适用于我,但事实证明它是文件权限。我必须进入高级 Windows 文件权限并设置它们。

    如果您与成千上万的其他人一起遇到此问题并认为这不是文件权限并且您已经检查过它们...请再次检查它们。

    【讨论】:

      猜你喜欢
      • 2012-07-03
      • 2011-06-05
      • 1970-01-01
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多