barkster Posted December 1, 2008 Share Posted December 1, 2008 I'm trying to access some files under the home directory, the script accessing the file is in the following directory /home/user/public_html/beta/java/test.php I would think I could access the files in the home directory this way but cannot if(file_exists("/home/user/protected/test.txt")) echo "yes"; but I can only access it this way? What am I doing wrong? Is it trying to reference off of /public_html folder instead? How do I do it from /home dir? Thanks if(file_exists("../../../protected/test.txt")) echo "Yipee"; Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted December 1, 2008 Share Posted December 1, 2008 its because file paths are relative to the file you are currently accessing if(file_exists("/home/user/protected/test.txt")) is looking for the file /home/user/public_html/beta/java/home/user/protected/test.txt the ../ backs you up a folder does that make sense? Quote Link to comment Share on other sites More sharing options...
haku Posted December 1, 2008 Share Posted December 1, 2008 You can't reference folders above public_html using root-level relative paths, because they reference everything from public_html. So you will need to use ../../../protected/test.txt Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted December 1, 2008 Share Posted December 1, 2008 thats a much better answer haku, thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 1, 2008 Share Posted December 1, 2008 When you try if(file_exists("/home/user/protected/test.txt")) echo "yes"; with php error_reporting set to E_ALL and display_errors set to ON, what error do you get? That would indicate why it is not working. This could be a permissions, open_basedir, or an incorrect path problem. Quote Link to comment Share on other sites More sharing options...
barkster Posted December 1, 2008 Author Share Posted December 1, 2008 Thanks, I'll stick with what I have, figured that is what was happening but I just though putting the / in from indicated from "root" but the real root is the "public_html" folder and not the home dir. PFMaBiSmAd, I was just getting access denied cause the folder didn't exist. Thanks for the clarification! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.