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:

    <li>/application</li> <li>/application/controllers</li> <li>/public (Document Root)</li> </ul>

    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.


    file_exists() will work anywhere, it has nothing to do with the document root and there are no apache config settings that can change this.

    There are two possible issues that could cause your problem:

      <li>the relative path is not relative to what you think it is. Please use an absolute path and edit your question to show the code you used to check the absolute path (the code you posted in comments had a mistake by the way)</li> <li>the UNIX process running PHP does not have permission to access that file. Please check what user PHP is running as and check the permissions of the file.</li> </ul>


      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!


  • Image uploader, capital letters in JPG extension doesn't work
  • passing parameters in xml
  • Extending WP_List_Table / handling checkbox options in plugin administration
  • $interval not running, angularjs
  • Angular Dart $scope.$on functionality is not working
  • Check for file existence if Laravel's Blade template
  • C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App
  • Bootstrap Popover showing at wrong place upon zoom in/out or resizing Browser window
  • Mvc 3 posting content type application/json, action method arguments loose mapping?
  • Prevent page break in text block with iText, XMLWorker
  • how to get data attributes of dynamically generated element
  • Python 3.2.2, error(scripts to exe)
  • NSIS decompiler
  • I am receiving HibernateException “No Hibernate Session bound to thread, and configuration does not
  • Position: fixed nav does not stay fixed
  • JBoss External Properties Files in Classpath
  • How to use JavaScript to determine whether a file exists in a directory?
  • ADO and msqli connections very slow
  • Problem while Building a Setup Project for a windows Service?
  • htaccess add www if not subdomain, if subdomain remove www
  • How do I get HTML corresponding to current DOM tree?
  • PHP buffered output depending on server setting?
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Change an a tag attribute in JavaScript based on screen width
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • A cron job substitute?
  • json Serialization in asp
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal