Re: Re: best way to properly build an include path *regardless* from where I am calling the include?

From: Date: Mon, 06 Jul 2009 02:07:27 +0000
Subject: Re: Re: best way to properly build an include path *regardless* from where I am calling the include?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-294913@lists.php.net to get a copy of this message
Govinda wrote: > > On Jul 5, 2009, at 6:15 PM, Shawn McKenzie wrote: >> >> AFAIK, include '/somedir/somefile.php'; looks for that specific file in >> that specific path because you gave an absolute path. > > Well, that is what I wanted. > So I tried this: > include '/MY_inc_php/GovBC_php_functions.inc'; > but that fails. > So I try this: > include '/home/metheuser/public_html/MY_inc_php/GovBC_php_functions.inc'; > and it works. So, depending upon you include path, yes. The preceding slash states that its an absolute path. Starts at the root / nad the a path after that. > > But if I ever have to move to a server where the "home" part of that > path is not "home", or the "public_html" part of that path is not > "public_html" (I dunno.. I do not run servers), then my includes break. > >> >> If you do include 'somedir/somefile.php'; then it looks in all paths in >> the include path > > Here ^^^ when you say "it looks in all paths in the include path", what > are you talking about? > It seem like you do not mean the path in my include statement itself, > but in some string (path) that is built and stored somewhere else. (?) > Where do I build/store that? > >> 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. > > > In include_path in php.ini or you can set it in your script. It's the path that PHP looks in when you include a file. Sorry, I thought you knew this and were wanting to know whey one thing worked and one didn't. -- Thanks! -Shawn http://www.spidean.com

« previous php.general (#294913) next »