Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?
From: randy (sesser_at_gmail.com)
Date: 02/07/05
- Next message: Erwin Moller: "Re: PHP file upload unexpected error - file too large?"
- Previous message: Giulio Neri: "Re: PHP file upload unexpected error - file too large?"
- In reply to: Tom: "__FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Next in thread: randy: "Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Reply: randy: "Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Feb 2005 07:34:12 -0800
If your host is using any symbolic links (which I suspect they are),
realpath() will resolve those symbolic links. I'm guessing this is
what's causing the discrepency. I'm just using dirname(__FILE__) to set
a constant for the script root. It seems to work well so far. The only
downside to this is that you have have the __FILE__ in the root of your
application.
hth
r.
Tom wrote:
> I'm trying to dynamically adjust the path for one of my scripts using
> this:
>
> $script_path = str_replace( $_SERVER['DOCUMENT_ROOT'], "",
> dirname(realpath(__FILE__)) ) . DIRECTORY_SEPARATOR;
>
> The problem: the server I'm currently testing it on returns for
> $_SERVER['DOCUMENT_ROOT'] something like the path "home/user/path/"
and
> for __FILE__ "home2/user/path/scriptdir/" I tried to trace the
> discrepancy running phpinfo, but the only reference I can find to
> "home2" there is _ENV["PWD"].
>
> Anyway, this is throwing all my best laid plans into confusion. Can
> someone help me understand why $_SERVER['DOCUMENT_ROOT'] and __FILE__
> are returning different basepaths?
>
> And how I might get my script to do what I'd like it to do
(basically,
> return the directory path of my script minus the document root so
that
> I can then append it to the absolute URL)?
>
> Hope this makes sense. Thanks,
>
> Tom
- Next message: Erwin Moller: "Re: PHP file upload unexpected error - file too large?"
- Previous message: Giulio Neri: "Re: PHP file upload unexpected error - file too large?"
- In reply to: Tom: "__FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Next in thread: randy: "Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Reply: randy: "Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|