By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,510 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,510 IT Pros & Developers. It's quick & easy.

absolute paths

P: n/a
do I have to prefix every absolute path with document root to get it to
work?

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?

e.g., when I do

include './Scripts/AddNav.php';

or

include '/Scripts/AddNav.php';

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?

Thanks,
Jon
Apr 21 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
>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.

Apr 21 '07 #2

P: n/a

"Gordon Burditt" <go***********@burditt.orgwrote in message
news:13*************@corp.supernews.com...
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.
No, only file paths... shit... I guess ;/ Didn't realize there was a
difference?

When someone uses my site: www.jonslaughter.com/somedir/somefile.php, can
everything after the domain name be considered a file path? (atleast if it
actually looks like a file path)

That is, on my site I will be using file paths to represent url paths.
Theres a one to one correspondence between the urls and files. (excluding
the additional domain name and protocol in the url)
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

Ok, but what I am doing is only keeping the /images/flag.jpg

so maybe I'll have a file in document_root that opens the flag.jpg

if I do something like read('/images/flag.jpg') then it works because it
uses the relative dir scheme. But now if I wasn't in document root then it
wouldn't(assuming there is no /images/flag.jpg in that dir)

>>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.
ok. I guess thats it then. I thought then that you could use absolute urls
and the would be resolved w.r.t to 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.
ok.

So essentially what your saying is that there is no such thing as absolute
file paths? That is, all file paths are relative?
>
>>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.
YEah, I thought about that. I haven't got the autoinclude stuff to work but
was just going to create a function like ap(somepath) that would prefix
somepath with the document root.

I just needed to understand the difference. I didn't realize that there
were url and file paths and that only urls had the absolute ability. I think
I got it now though.

Thanks,
Jon
Apr 22 '07 #3

P: n/a
Jon Slaughter wrote:
"Gordon Burditt" <go***********@burditt.orgwrote in message
news:13*************@corp.supernews.com...
>>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.

No, only file paths... shit... I guess ;/ Didn't realize there was a
difference?

When someone uses my site: www.jonslaughter.com/somedir/somefile.php, can
everything after the domain name be considered a file path? (atleast if it
actually looks like a file path)

That is, on my site I will be using file paths to represent url paths.
Theres a one to one correspondence between the urls and files. (excluding
the additional domain name and protocol in the url)
>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


Ok, but what I am doing is only keeping the /images/flag.jpg

so maybe I'll have a file in document_root that opens the flag.jpg

if I do something like read('/images/flag.jpg') then it works because it
uses the relative dir scheme. But now if I wasn't in document root then it
wouldn't(assuming there is no /images/flag.jpg in that dir)

>>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.

ok. I guess thats it then. I thought then that you could use absolute urls
and the would be resolved w.r.t to 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.

ok.

So essentially what your saying is that there is no such thing as absolute
file paths? That is, all file paths are relative?
>>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.

YEah, I thought about that. I haven't got the autoinclude stuff to work but
was just going to create a function like ap(somepath) that would prefix
somepath with the document root.

I just needed to understand the difference. I didn't realize that there
were url and file paths and that only urls had the absolute ability. I think
I got it now though.

Thanks,
Jon

Jon,

If it's being accessed using http protocol (i.e.
http://www.example.com/myfile.php) it is a URI and relative to your
document root.

If it's being accessed from your php code, i.e. by include (_once),
require (_once), fopen (to the local filesystem) it's relative to the
root directory of your machine.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 22 '07 #4

P: n/a

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:WO******************************@comcast.com. ..
Jon Slaughter wrote:
>"Gordon Burditt" <go***********@burditt.orgwrote in message
news:13*************@corp.supernews.com...
>>>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.

No, only file paths... shit... I guess ;/ Didn't realize there was a
difference?

When someone uses my site: www.jonslaughter.com/somedir/somefile.php, can
everything after the domain name be considered a file path? (atleast if
it actually looks like a file path)

That is, on my site I will be using file paths to represent url paths.
Theres a one to one correspondence between the urls and files. (excluding
the additional domain name and protocol in the url)
>>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


Ok, but what I am doing is only keeping the /images/flag.jpg

so maybe I'll have a file in document_root that opens the flag.jpg

if I do something like read('/images/flag.jpg') then it works because it
uses the relative dir scheme. But now if I wasn't in document root then
it wouldn't(assuming there is no /images/flag.jpg in that dir)

>>>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.

ok. I guess thats it then. I thought then that you could use absolute
urls and the would be resolved w.r.t to 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.

ok.

So essentially what your saying is that there is no such thing as
absolute file paths? That is, all file paths are relative?
>>>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.

YEah, I thought about that. I haven't got the autoinclude stuff to work
but was just going to create a function like ap(somepath) that would
prefix somepath with the document root.

I just needed to understand the difference. I didn't realize that there
were url and file paths and that only urls had the absolute ability. I
think I got it now though.

Thanks,
Jon


Jon,

If it's being accessed using http protocol (i.e.
http://www.example.com/myfile.php) it is a URI and relative to your
document root.

If it's being accessed from your php code, i.e. by include (_once),
require (_once), fopen (to the local filesystem) it's relative to the root
directory of your machine.
Ok, thanks. I didn't know there was a differentiation.
Apr 22 '07 #5

P: n/a
>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.

No, only file paths... shit... I guess ;/ Didn't realize there was a
difference?

When someone uses my site: www.jonslaughter.com/somedir/somefile.php, can
everything after the domain name be considered a file path? (atleast if it
actually looks like a file path)

That is, on my site I will be using file paths to represent url paths.
My bet is that the document root of your web site is NOT / .
And it certainly shouldn't be.
>Theres a one to one correspondence between the urls and files. (excluding
the additional domain name and protocol in the url)
No, there isn't. There should be *NO* URL that pulls up the file
/etc/passwd from your system. Or in the case of Windows, there should
be *NO* url for the files containing the registry, or any of the files
in the Windows system directory. There should be *NO* URL that pulls up
most of the executables for your system, as they might be copyrighted
and your license may not permit you to distribute them without the
corresponding source code. Besides, nasty people will see you have
unpatched executables and try to crack your system.

Your URL might be: http://www.jonslaughter.com/images/flag.jpeg
The corresponding file might be:
/usr/local/www/document_root/images/flag.jpeg
>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


Ok, but what I am doing is only keeping the /images/flag.jpg

so maybe I'll have a file in document_root that opens the flag.jpg
Files do not open other files.
>if I do something like read('/images/flag.jpg') then it works because it
uses the relative dir scheme. But now if I wasn't in document root then it
wouldn't(assuming there is no /images/flag.jpg in that dir)
To further confuse things, there is the PHP setting include_dir,
and PHP does have a current working directory, which you can change.
I suspect a lot of what you claim about how things work will suddenly
break if these are changed.

On my system, I have an include directory which is *OUTSIDE* the
document root, for, among other things, database login and password
information. This directory is listed, by absolute FILE path, in
include_path. I can refer to a particular file containing a
particular database login for a particular application with:
include "tv.inc";
from *ANY* PHP script on any of several virtual hosts, in one of
the document root directories or several levels below that, and
I'll always get the file. The only caveat is that I can't leave
a different "tv.inc" file around in the same directory as one of
the scripts. Even that I could fix by putting the path to my include
directory *FIRST* in include_path, or leave "." out of it entirely.
>>>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.

ok. I guess thats it then. I thought then that you could use absolute urls
and the would be resolved w.r.t to the document root.
You can use an absolute URL *IN A BROWSER* and they will be resolved with
respect to the document root. That is *NOT* true of "include".
>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.

ok.

So essentially what your saying is that there is no such thing as absolute
file paths? That is, all file paths are relative?
No, there are absolute file paths. File paths are what you use
with a shell, and what you get back when you type "pwd". There
won't be any URL paths to files on your system if you remove the
web server (and therefore, PHP).

Look at it this way: You have to use a file path where a file path
is required and you have to use a URL path where a URL path is
required. In some places you can use either but a URL path has to
start with "http:". You can't mix them, just like you cannot dial
a postal address nor can you put a phone number and a stamp on a
letter and expect it to arrive at the correct place. It may be
that in your office complex, your office number is both the last 3
digits of your phone number AND it's the last 3 digits of your (USA,
9-digit) zip code. You can use a short-cut reference (relative
path) to your office by just office number, but not when talking
to someone in a different building.

>>>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.

YEah, I thought about that. I haven't got the autoinclude stuff to work but
was just going to create a function like ap(somepath) that would prefix
somepath with the document root.
Fine. Now how do you define that function? With include, or require,
probably. Otherwise it's a lot more work than
include $_SERVER['DOCUMENT_ROOT'].'/Scripts/AddNav.php';
>
I just needed to understand the difference. I didn't realize that there
were url and file paths and that only urls had the absolute ability. I think
I got it now though.

Thanks,
Jon


Apr 22 '07 #6

P: n/a
On Apr 22, 1:24 am, gordonb.n5...@burditt.org (Gordon Burditt) wrote:
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.
No, only file paths... shit... I guess ;/ Didn't realize there was a
difference?
When someone uses my site:www.jonslaughter.com/somedir/somefile.php, can
everything after the domain name be considered a file path? (atleast if it
actually looks like a file path)
That is, on my site I will be using file paths to represent url paths.

My bet is that the document root of your web site is NOT / .
And it certainly shouldn't be.
Theres a one to one correspondence between the urls and files. (excluding
the additional domain name and protocol in the url)

No, there isn't. There should be *NO* URL that pulls up the file
/etc/passwd from your system. Or in the case of Windows, there should
be *NO* url for the files containing the registry, or any of the files
in the Windows system directory. There should be *NO* URL that pulls up
most of the executables for your system, as they might be copyrighted
and your license may not permit you to distribute them without the
corresponding source code. Besides, nasty people will see you have
unpatched executables and try to crack your system.

Your URL might be:http://www.jonslaughter.com/images/flag.jpeg
The corresponding file might be:
/usr/local/www/document_root/images/flag.jpeg


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
Ok, but what I am doing is only keeping the /images/flag.jpg
so maybe I'll have a file in document_root that opens the flag.jpg

Files do not open other files.
if I do something like read('/images/flag.jpg') then it works because it
uses the relative dir scheme. But now if I wasn't in document root then it
wouldn't(assuming there is no /images/flag.jpg in that dir)

To further confuse things, there is the PHP setting include_dir,
and PHP does have a current working directory, which you can change.
I suspect a lot of what you claim about how things work will suddenly
break if these are changed.

On my system, I have an include directory which is *OUTSIDE* the
document root, for, among other things, database login and password
information. This directory is listed, by absolute FILE path, in
include_path. I can refer to a particular file containing a
particular database login for a particular application with:
include "tv.inc";
from *ANY* PHP script on any of several virtual hosts, in one of
the document root directories or several levels below that, and
I'll always get the file. The only caveat is that I can't leave
a different "tv.inc" file around in the same directory as one of
the scripts. Even that I could fix by putting the path to my include
directory *FIRST* in include_path, or leave "." out of it entirely.
>>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.
ok. I guess thats it then. I thought then that you could use absolute urls
and the would be resolved w.r.t to the document root.

You can use an absolute URL *IN A BROWSER* and they will be resolved with
respect to the document root. That is *NOT* true of "include".


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.
ok.
So essentially what your saying is that there is no such thing as absolute
file paths? That is, all file paths are relative?

No, there are absolute file paths. File paths are what you use
with a shell, and what you get back when you type "pwd". There
won't be any URL paths to files on your system if you remove the
web server (and therefore, PHP).

Look at it this way: You have to use a file path where a file path
is required and you have to use a URL path where a URL path is
required. In some places you can use either but a URL path has to
start with "http:". You can't mix them, just like you cannot dial
a postal address nor can you put a phone number and a stamp on a
letter and expect it to arrive at the correct place. It may be
that in your office complex, your office number is both the last 3
digits of your phone number AND it's the last 3 digits of your (USA,
9-digit) zip code. You can use a short-cut reference (relative
path) to your office by just office number, but not when talking
to someone in a different building.


>>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.
YEah, I thought about that. I haven't got the autoinclude stuff to work but
was just going to create a function like ap(somepath) that would prefix
somepath with the document root.

Fine. Now how do you define that function? With include, or require,
probably. Otherwise it's a lot more work than
include $_SERVER['DOCUMENT_ROOT'].'/Scripts/AddNav.php';


I just needed to understand the difference. I didn't realize that there
were url and file paths and that only urls had the absolute ability. I think
I got it now though.
Thanks,
Jon- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
I always did something like this.. I Can't remember the exact $_Server
part b/c I am not at home, but it goes something like that where
$_Server is http://www.orbstra.com/ and then I toss guava/ at the end.

class get
{
function url()
{
return ($_SERVER['URL'] . guava/);
}
}

so when I need to:

include get::url() . 'system/';

So on and so forth...

Apr 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.