|
Posted by Jerry Stuckle on 04/22/07 02:41
Jon Slaughter wrote:
> "Gordon Burditt" <gordonb.8oiz7@burditt.org> wrote in message
> news:132l8tv69kc6d6f@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.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|