Forum Moderators: coopster

Message Too Old, No Replies

$document_root problem

         

Smad

7:45 am on Oct 29, 2004 (gmt 0)

10+ Year Member



I have read numerous posts on using $document_root and to my understanding what i am trying should work.

i am trying to establish a path structure which didnt work using $document_root so i have to use the domain instead. (this is for includes and css files btw)

1. [mydomain.com...] (works)

2. /images/image.jpg (works)

3. $DOCUMENT_ROOT/images/image.jpg (doesn't)

am i right in assuming $DOCUMENT_ROOT is like using the number 1 method or have i misunderstood it?

please help.

TIA

Code Sentinel

8:06 am on Oct 29, 2004 (gmt 0)

10+ Year Member



$DOCUMENT_ROOT itself may not work if globals aren't enabled(not sure if it would even if they are).

you need to use $_SERVER['DOCUMENT_ROOT']

it functions the same as your first example BUT it doesn't work the same :) the document root is basically the web root local path of your user directory on the server.

when you log into ftp or cpanel file manager you start off in "/home/user/" which is above the web root directory. The contents of your site or home page [example.com...] is usually found or starts in "/home/user/public_html/" or something similar which is the web root.

$_SERVER['DOCUMENT_ROOT'] refers to this directory(/home/user/public_html)

that's how I understand it, if I'm wrong with a certain aspect then someone correct please.

Smad

8:22 am on Oct 29, 2004 (gmt 0)

10+ Year Member



yes globals are on, so regarding setting up a path that works for any directory. $document_root would be the way to go? so www.mydomain.com/home/users/public_html/images/image.jpg is the same as www.mydomain.com/images/image.jpg? if it is, is there a reason why it wouldnt work.

charlier

8:22 am on Oct 29, 2004 (gmt 0)

10+ Year Member



Put a phpinfo(); statement at the top of your code and you will see all the variables that you can access, along with tons of other information.

You can usually get the document root from the $_SERVER[] array along with path information to the page reqeuest etc.

Code Sentinel

12:03 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



/home/username/public_html/ is to the server as / or www.mydomain.com/ is to the browser.

www.mydomain.com/home/username/public_html/images/image.jpg would then be /home/username/public_html/home/username/public_html/images/image.jpg

while

www.mydomain.com/images/image.jpg would be the same as /home/username/public_html/images/image.jpg

so I just think of $_SERVER['DOCUMENT_ROOT'] as / or www.mydomain.com/