Re: include question
| From: | Nathan Rixham | Date: | Sat, 07 Mar 2009 19:20:14 +0000 |
| Subject: | Re: include question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-289556@lists.php.net to get a copy of this message | ||
Daniel Brown wrote:
On Fri, Mar 6, 2009 at 08:53, Stuart <stuttle@gmail.com> wrote:that's the way i do it, for example require_once realpath( dirname(__FILE__) . '/lib/LibAllTests.php' ); also I often use set_include_path to ensure everything works throughout, it's a lot simpler for require/includes set_include_path( get_include_path() . PATH_SEPARATOR . realpath( dirname(__FILE__) . DIRECTORY_SEPARATOR ) ); for example.. then all subsequent requires will be: require_once 'Folder/file.php'; regards5.) dirname() gives you the full path on disk, not the URL. Usually you can just remove the document root path to get the URL. This could be in $_SERVER['DOCUMENT_ROOT'] but you can't rely on that between servers or when the config changes.1.) We use regular open tags to be compatible with all stockPHP configurations.2.) We echo out the response from dirname() so that it'soutput to the HTML source.3.) We use dirname() twice, so it gives the dirname() of thedirname(), rather than '..'.4.) There are double underscores around FILE. The same istrue with LINE, FUNCTION, etc.6.) When used in conjunction with realpath()[1], it willresolve the absolute local pathname.^1: http://php.net/realpath