In response to
’…’ means folder above this one.
use …/…/etc/… to navigate through and find the folder you want.
I have a file, it’s located in http://website/users/abyss
I want it to include a file from http://website/ - In this case, you include …/…/filename
Say, you’re in /users/abyss, and want a file in /users/foo
Do: include …/foo/filename .
Do these relative to the location of the file you have the include statement in.
I tried to explain it best as I can, Understand? xD"
Thanks. I do understand the …/ traversing up a level in the directory tree. My issue was with how to handle it for files in different levels of my site. Since I use the same include files to do basic functionality where needed from all pages in my site that need them, files they themselves may need to include are in different relative paths to the page being loaded. And unfortunately, php looks for files relative to the main script rather than the script looking for the file.
So if I have a structure like…
and pages in /www and pages in /www/admin load the same file out of the /www/includes folder to then relatives paths inside those files are different.
I had handled this before by placing a locals.php file in each folder, and it defines settings required by pages in that particular folder. Among them is $RootPath which contains the relative path to the root of my site.
So locals for /www has $RootPath = ‘’;
For /www/admin $RootPath = ‘…/’ ;
Then in my include or require statements I always use the $RootPath variable if I need to get down to my main includes or whatever other directories.
require_once($RootPath . ‘includes/someincludesfile.php’);
It works just fine in this case as well. I don’t know why using relative paths didn’t cross my mind for getting down below my web directory as well.
require_once($RootPath . ‘…/blah/someglobals.php’);
gets me my globals file just fine as well, and since I already have $RootPath defined and available to all my pages, I’m good to go.
Thanks everyone for the suggestions.