Search code examples
phpapachefile-existsdocument-root

PHP file_exists not working outside document root


I have the following directory structure where the Document Root is pointed to /var/www/html/public:

  • /application
  • /application/controllers
  • /public (Document Root)

I am trying to use the following code to check if a file exists inside a file in the /public directory (working on local setup, but not on live server)

<?php 
if (file_exists('../application/controllers/TestController.php'))
{
    /* do something */
}

Could there be something in the Apache config file the I need to add? I am not sure where to go from here.


Solution

  • So the real problem that I found was that on my live server, the file name did not change when I renamed it to lowercase (APIController => ApiController). Even though the change happened locally, my GIT commit did not rename the file properly when the code was committed.

    Sorry for the confusion!