【问题标题】:why file_exists always return false when put value as param?为什么当将值作为参数时,file_exists 总是返回 false?
【发布时间】:2019-01-29 19:32:41
【问题描述】:

我有这样的功能:

public function asset_exists($path)
{
    $webRoot = realpath($this->kernel->getRootDir() . '/../web/');
    $toCheck = $webRoot . $path;
    if (!file_exists("/Users/mtmac/app/app-web/web/uploads/clients/5b7e824a97ba4.jpeg"))
    {
        return false;
    }
    return true;
}

当我将值作为字符串放在 file_exists 函数上时,一切正常。

问题是当我更改 IF 条件时

if (!file_exists($toCheck))
    { return false; }

我总是从那个条件得到返回值 FALSE。

注意:

一个。图像存在于磁盘上

b.参数$toCheck的值为
/Users/mtmac/app/app-web/web/uploads/clients/5b7e824a97ba4.jpeg

【问题讨论】:

标签: php file-exists


【解决方案1】:

免责声明:我不是 PHP 开发人员。回答这个问题是因为我觉得它很有趣并想到了挖掘。

现在,您面临的问题似乎与 .htaccess 文件中设置的 php include_path 值有关。

这是 php.net 上关于类似问题的评论。 http://php.net/manual/en/function.file-exists.php#49805

以下是我引用的评论的摘录:

我花了两个小时想知道我的 if 语句出了什么问题:file_exists($file) 返回 false,但是我可以毫无问题地调用 include($file)。

原来我没有意识到我在.htaccess文件中设置的php include_path值并没有延续到file_exists、is_file等。

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-02
    • 2012-02-23
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    相关资源
    最近更新 更多