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.

Tim Kipp
  • 200
  • 1
  • 16
  • 2
    your if statement doesnt have open and close parenthesis. is that a typo? – Kevin Oct 23 '14 at 03:04
  • which directory is that script running in ? does `if (file_exists('var/html/www/public/application/controllers/TestController.php'))` work ? –  Oct 23 '14 at 03:16
  • @Dagon it is running in the /public directory. /public/index.php to be exact. – Tim Kipp Oct 23 '14 at 03: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. – miken32 Oct 23 '14 at 03: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? – Tim Kipp Oct 23 '14 at 03:24
  • that does not match what you have written above, by regardless if the absolute does not work, check the permissions of the script\file\directory –  Oct 23 '14 at 03:26
  • @Dagon yes, the absolute path does match what I posted, (you posted it wrong. look at my post at the directory structure...) – Tim Kipp Oct 23 '14 at 03:28
  • how does `/var/html/www/public` = `/var/www/html/` –  Oct 23 '14 at 03:29
  • @Dagon what are you talking about? the path to my DocumentRoot on my server is /var/www/html/public. miken32 and you both posted the wrong path, not me. – Tim Kipp Oct 23 '14 at 03:33
  • where do you think we got the path from? its in your post, we just copied it. –  Oct 23 '14 at 03:48
  • @Dagon Oh wow!! I totally spaced...Sorry about calling you out when I was the one in the wrong. I have updated the original post. I'm dumb haha – Tim Kipp Oct 23 '14 at 03:50

2 Answers2

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.
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
  • @Dagon comments are too short to describe all the details. Better to post an answer. – Abhi Beckert Oct 23 '14 at 03:32
  • @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. – Tim Kipp Oct 23 '14 at 03:52
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!

Tim Kipp
  • 200
  • 1
  • 16