2

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.

11
  • 2
    your if statement doesnt have open and close parenthesis. is that a typo? Commented Oct 23, 2014 at 3:04
  • which directory is that script running in ? does if (file_exists('var/html/www/public/application/controllers/TestController.php')) work ? Commented Oct 23, 2014 at 3:16
  • @Dagon it is running in the /public directory. /public/index.php to be exact. Commented Oct 23, 2014 at 3:18
  • 2
    Could be a permissions problem. Does ls -l /var/www/html/www/public/application/controllers/ give you any hints? I'd second the above suggestion to try absolute file paths as well. Commented Oct 23, 2014 at 3:19
  • @miken32 the absolute path did not work either. and the path would be /var/www/html/application/controllers/. I did notice that the owner of the file I'm trying to check for is owned by a user that is NOT root, could that be the issue? Commented Oct 23, 2014 at 3:24

2 Answers 2

2

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:

  • 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)
  • 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.
Sign up to request clarification or add additional context in comments.

2 Comments

@Dagon comments are too short to describe all the details. Better to post an answer.
@AbhiBeckert thanks for the suggestions. fortunately, it was an issue with a file name case difference that GIT did not rename properly. those are good tips for anyone else that may experience these issues.
0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.