-2

I have a function like this :

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;
}

Everything is working well when I put value as string on file_exists function.

THE ISSUE IS When I change that IF conditional

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

I always get return value FALSE from that condition.

NOTE :

a. The image is exists on disk

b. The value of param $toCheck is
/Users/mtmac/app/app-web/web/uploads/clients/5b7e824a97ba4.jpeg

yivi
  • 42,438
  • 18
  • 116
  • 138

1 Answers1

-1

Disclaimer: I am not a PHP developer. Responding to this question because I found it interesting and thought of digging.

Now, the problem you are facing seems to be related with php include_path value set in the .htaccess file.

Here is the comment on php.net talking about similar problem. http://php.net/manual/en/function.file-exists.php#49805

Here is some excerpts from the comment I have referred:

I spent the last two hours wondering what was wrong with my if statement: file_exists($file) was returning false, however I could call include($file) with no problem.

It turns out that I didn't realize that the php include_path value I had set in the .htaccess file didn't carry over to file_exists, is_file, etc.

Hope this helps!

Community
  • 1
  • 1
dj079
  • 1,389
  • 8
  • 14