In php, I’m trying to read a file that is placed above the web root (e.g. /home/[username]/games/). I am trying to read a .swf and an .xml file. I have it working well on my local LAMP server, using this code:
@readfile("/home/[username]/games/hangman/example.xml");
But, testing it on an external server, it doesn’t work. No php errors are in the log, but when I try file_exists(), it returns false. I have checked, and double checked, that the file exists at that path.
File permissions seem to be correct (they are the same as my local server), and the owner of the file is the correct user.
Edit
A bit of an update; I followed what @gnur had to say and set my basename in my httpd.conf in the virtual host setting as:
php_admin_value open_basedir "/:/home/[username]/games/"
I tried setting it do a different value before, and it was throwing an error:
open_basedir restriction in effect. File(/home/[username]/games/example.xml) is not within the allowed path
Now, I just get a permission denied error when trying to read the file. So I’m wondering if the file permissions, or the owner, isn’t right.
These are my current permissions on the folder under the games directory:
drwxrwxr-x 2 [username] [username] 4.0K Jun 1 10:13 hangman
And then the files underneath that directory (The ones that I’m actually trying to access):
-rwxrwxr-x 1 [username] [username] 293 Jun 1 10:13 example.xml
-rwxrwxr-x 1 [username] [username] 204K Jun 1 10:13 hangman.swf
This has something to do with the
open_basedirvalue of php.ini, see http://php.net/manual/en/ini.core.php for more information.