【问题标题】:file_exists() returns false, even for paths that do existfile_exists() 返回 false,即使对于确实存在的路径
【发布时间】:2012-01-31 05:30:30
【问题描述】:

好的程序员,我想在新年之前解决这个问题。我只想在照片存在时显示照片,否则使用默认照片。这是我始终正确返回“文件存在”的代码

<?php 
    $photolocation = '../wp-content/gallery/playerphotos/Joe Smith.jpg';
    if (!file_exists($photolocation))
    {
        echo "File exists";
    }
    else
    {
        echo "File does not exist";
    }
?>

当我将photolocation 更改为:

$photolocation = '../wp-content/gallery/playerphotos/XXX Smith.jpg';

我错误地得到“文件存在”。

我不明白为什么条件 !file_exists 总是返回一个正值。

【问题讨论】:

  • 您意识到您是在要求您的if 评估该文件是否 存在?因此,您应该只在文件存在时才获得file exists...除非我真的误解了file_exists() 函数的某些内容。
  • @DavidThomas 是对的。从 if 条件中删除 NOT !
  • 我同意@DavidThomas 和@xbonez。问题是,这也意味着你的路径都不起作用。

标签: php webpage displayobject


【解决方案1】:

应该是:

<?php 
    $photolocation = '../wp-content/gallery/playerphotos/XXX Smith.jpg';

    if (file_exists($photolocation))
    {
        echo "File exists";
    }
    else
    {
        echo "File does not exist";
    }
?>

【讨论】:

  • 我认为我的问题可能与服务器不允许遵循符号链接有关。这有意义吗?这似乎是一个简单的问题......但我已经浪费了很多时间。
  • @DoubleA 您能否编辑您的问题以注意$photolocation 的哪一部分是符号链接?此外,如果您包含 getcwd() 的输出,也会有所帮助。
  • 你在运行什么操作系统/网络服务器?
猜你喜欢
  • 2016-05-28
  • 2011-10-19
  • 2016-01-13
  • 2012-05-13
  • 2017-08-15
  • 2012-03-01
  • 2012-09-02
  • 2017-10-03
  • 2012-02-23
相关资源
最近更新 更多