Ok i’ve run across this problem a few times in my programming life, where file_exists always returns false. I don’t think i’ve ever properly fixed it. Generally I make some crappy work around, which ends up causing more harm than good.

So here’s a small checklist to solve the problem.

  1. Check the file path you are actually sending the function. eg file_exists(BASE_DIR . “/images/image1.jpg”);
    • I always like to do a print_r on whatever is in between the brackets just to make sure i’m not completely inept.
    • For this example i have too many ‘/’ that could be causing me dilemmas.
  2. Check that the folders/files you are accessing don’t have any safe mode restrictions.
  3. If those 2 solutions didn’t work and you have ensured you have passed the correct file path then put a call to the function “clearstatcache()” before the file_exists function.

If you still have problems even after that, then send me a comment and I’ll help you debug it.

Happy Coding

Bookmark and Share