Jump to content

[SOLVED] Including from the root directory.


justcrapx

Recommended Posts

I have an include folder for my scripts inside the root dir, all scripts are also included in the root. When i moved some of my scripts to a spesific folder the include function seeks the file inside that spesific directory, i want to target the original inc folder.

 

this is the include line

 

include 'inc/functions.php';

 

i have tried this but didnt work

 

include '../inc/functions.php';

Link to comment
https://forums.phpfreaks.com/topic/36979-solved-including-from-the-root-directory/
Share on other sites

well, it depends on where your file resides.

 

for instance, here is a basic layout for a site with includes:

 

-root

--inc (dir)

--admin(dir)

---users(dir)

---mods(dir)

--themes

 

 

In the case like this - include('../inc/functions.php') a script with this included inside the mods dir, would look for the folder inc in the admin dir, instead of the root dir. to make it look deeper for the root dir, add another .., like include('../../inc/functions.php') if thats not it, I have no clue dude

You can use the $_SERVER['DOCUMENT_ROOT'] variable to access the root directory.

 

when I looked this up earlier (because thats what I was going to say as well) it said that $_SERVER['DOCUMENT_ROOT'] was only the root folder for the script was running in - does this mean it is the folder the script resides in, or the root folder for the server?

You can use the $_SERVER['DOCUMENT_ROOT'] variable to access the root directory.

 

when I looked this up earlier (because thats what I was going to say as well) it said that $_SERVER['DOCUMENT_ROOT'] was only the root folder for the script was running in - does this mean it is the folder the script resides in, or the root folder for the server?

 

The root directory where apache serves files for the server.

 

EDIT: Decided to clarify.

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.