Jump to content

Access file in home directory?


barkster

Recommended Posts

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";

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.