|
Posted by Gordon Burditt on 04/21/07 23:52
>do I have to prefix every absolute path with document root to get it to
>work?
An absolute *FILE* path or absolute *URL* path? There are important
differences.
If you are attempting to use a URL path as an absolute file path,
yes, you have to prefix it with document root.
A file path might be used like this (on UNIX; try DIR on Windows):
ls -l /usr/local/www/document_root/images/flag.jpg
A URL path might be used like this:
http://myhost.mydomain.com/images/flag.jpg
>For some reason I thought that prefixing a path with '/' or './' with make
>it absolute w.r.t to document root but I guess not?
If you mean something like:
SRC="/images/flag.jpg"
just prefixing it with / makes it an absolute URL. To get a *FILE* path,
you need to prefix the document root.
If you prefix "./", you're making it relative (to *WHAT* depends on
context - for include, see include_path).
>
>e.g., when I do
>
>include './Scripts/AddNav.php';
>
>or
>
>include '/Scripts/AddNav.php';
include takes a *FILE* path.
>It only happens to work if that path is in the current directory but it
>won't goto the root directory.
>
>i.e., the above is doing the exact same as if I did
>
>include 'Scripts/AddNav.php';
>
>But in any case this doesn't work in general unless I use
>
>include $_SERVER['DOCUMENT_ROOT'].'/Scripts/AddNav.php';
>
>ofcourse this seems like a mess to do every time I want to use an absolute
>path... which is a lot.
>
>Is that what I'm stuck with doing or is there a function, say, like abp that
>will take a path and prefix the document root to it?
If you've got an include file that you include at the front of every
page, (PHP autoinclude?) you could include that one as above, and
inside it, set $ScriptDir and then:
include $ScriptDir.'/AddNav.php';
which is a little shorter.
Navigation:
[Reply to this message]
|