Re: best way to properly build an include path *regardless* from where I am calling the include?
| From: | Kim N. Lesmer | Date: | Sun, 05 Jul 2009 22:42:09 +0000 |
| Subject: | Re: best way to properly build an include path *regardless* from where I am calling the include? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294952@lists.php.net to get a copy of this message | ||
On Sun, 5 Jul 2009 14:33:07 -0600
Govinda <govinda.webdnatalk@gmail.com> wrote:
> I am confusing myself reading the docs just now.
>
> i.e.:
> include_path
> basename()
> and dirname()
>
> I had thought from many months ago that
> <?php include '/somedir/somefile.php'; ?>
> would include
> somefile.php
> living in
> somedir
> regardless from where in the site structure I am calling it.
>
> Now it does not seem to be doing that.
>
> What is the safest (portable) way to properly build an include path
> *regardless* from where in my site I am calling the include?
> If I understand right I can put includes in a dir/ specified by the
> include_path setting, but I also want to know how to do this from
> just within the root of my virtual server.
Like Michael said there is more than one way to deal with this.
I personally prefer to use this:
require_once ($_SERVER['DOCUMENT_ROOT'] . "/incl/myfile.php");
Unless the file needs to be kept outside of where the webserver serves
files.
> -Govinda
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
---
Mange venlige hilsner/Best regards
Kim Naim Lesmer
Programmer/Unix systemadministrator
Web : www.bitflop.com
E-mail : knl@bitflop.com