Re: best way to properly build an include path *regardless* from where I am calling the include?
| From: | Shawn McKenzie | Date: | Mon, 06 Jul 2009 00:15:43 +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-294907@lists.php.net to get a copy of this message | ||
Govinda 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.
>
> -Govinda
AFAIK, include '/somedir/somefile.php'; looks for that specific file in
that specific path because you gave an absolute path.
If you do include 'somedir/somefile.php'; then it looks in all paths in
the include path and appends somedir/somefile.php. So if your include
path contained /usr/share/php/PEAR for example and somefile.php was at
/usr/share/php/PEAR/somedir/ then it would find it.
--
Thanks!
-Shawn
http://www.spidean.com