Jump to content

Path to file above document root


FredAt

Recommended Posts

Hello All,

 

This is probably a very basic question but I cannot for the life of me figure out how to correctly refer to a file located above the document root.

 

$path = $_SERVER['DOCUMENT_ROOT'].'/../fldr_name/file.name';

 

is not giving the correct result. In answer to the inevitable question - I want to store a SQLite database in a folder above the server root for security. Naturally, I will need to access the file from some of my PHP scripts.

 

I am sure I have done this before and it has worked. Maybe it is just late in the day or maybe I am plain thick :'(. I'd appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/184010-path-to-file-above-document-root/
Share on other sites

I believe the DOCUMENT_ROOT adds the first slash for you, try this:

 

$path = $_SERVER['DOCUMENT_ROOT'].'../fldr_name/file.name';

 

If that does not work echo out $path and see where it could be going wrong, alternatively you can use explode at the / and put the items in an array and just remove the last item in the array.

Thanks.  Rule 1 (which I know well and break often) - never work beyond the point of uttter fatigue.

 

I started off by forgetting to create the safe SQLite database directory. Then I had too many slashes. Then I tested locally and got it right, uploaded to my Linux server and found it did not work. Eventually I realized that it was not liking my \ slashes and expected / slashes instead.

 

Enough for today!

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.