Hack Forums
[PHP] Global File access outside web directory. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Global File access outside web directory. (/showthread.php?tid=5837111)



Global File access outside web directory. - Dale Carnegie - May 15, 2018

In my server I have all the web directories for my websites in /web.
So /web/SITENAME/html/ Folders and files for that particular website.

Inside the HTML folder for each individual directory how do I link to a folder outside of that folder?

So let's say I have my index.php which is inside of sitename/html/ and inside the index file I want to link to another .php file that's outside of this directory. How would I go about doing that?
Normally in php you can simply do
PHP Code

<?php 
include 'filename' ; 
but that file is inside your current web directory. I need to link a file that's outside of this directory.

Hope i explained that well enough tried giving multiple examples.  

Thanks.

~ Dale


RE: Global File inside outer folder. - Nachfolger - May 15, 2018

You would include an upper directory by doing:
PHP Code

<?php 
include("../file_in_one_directory_up.php"); 

The ".." signify one directory up, so here's how to do something that's two up:
PHP Code

<?php 
include("../../file_two_directories_up.php"); 

And so on.


RE: Global File inside outer folder. - Dale Carnegie - May 15, 2018

(May 15, 2018 04:26 PM)Nachfolger Wrote:  You would include an upper directory by doing:
PHP Code

<?php 
include("../file_in_one_directory_up.php"); 

The ".." signify one directory up.

How would I go two directories up?

Setup:
Sitename/html/ current web directory.

So actually I'd need to go three levels up.


RE: Global File inside outer folder. - Nachfolger - May 15, 2018

(May 15, 2018 04:26 PM)Dale Carnegie Wrote:  How would I go two directories up?
Re-read my post. I was editing it as you quoted me.


RE: Global File access outside web directory. - Dale Carnegie - May 15, 2018

Thanks so much. Just saw your edit!


RE: Global File access outside web directory. - Squito - May 15, 2018

It only works as long as open_basedir is not in effect or the directory you want to reach is on the list of open_basedir directories.
PS: if a shared hosting does not have open_basedir set up it's better to avoid it.