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
https://forums.phpfreaks.com/topic/134930-access-file-in-home-directory/
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?

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.