Re: include_path and absolute paths in include functions
| From: | D. Dante Lorenso | Date: | Thu, 11 May 2006 22:00:04 +0000 |
| Subject: | Re: include_path and absolute paths in include functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236036@lists.php.net to get a copy of this message | ||
Steven Stromer wrote:
For years I was lulled into thinking I understood php include functions... I have always used relative paths in my include and related functions, for instance: include_once ("lib/included.php"); However, I am now needing to switch to absolute paths: include_once ("/lib/included.php"); This doesn't work. Generates error: Warning: main(/lib/included.php) [function.main.html]: failed to open stream: No such file or directory in /var/www/sites/sitename/index.php on line 8 Warning: main() [function.include.html]: Failed opening '/lib/included.php' for inclusion (include_path='.:/var/www/sites/sitename') in /var/www/sites/sitename/index.php on line 8You are confusing the web server's DOCUMENT_ROOT with your server's unix file system root directory '/'.
I would think I need to correct the include_path in php.ini, but the include_path seems right. The file I want to include does exist at: /var/www/sites/sitename/lib/included.php I always believed that the include_path and the path in the include() function were simply concatenated, but I now think that I am just plain wrong, as the error is reproducible on OS X, Fedora and everywhere else I test it. Am I not taking into account some other directive that affects include_path, like 'doc_root' in php.ini, or 'DocumentRoot' or 'ServerRoot' in httpd.conf? Or is this a permissions issue of some sort?If you want to include a file which stems from the DOCUMENT_ROOT, try something like this: * include_once($_SERVER['DOCUMENT_ROOT']."/lib/included.php"); Since absolute paths are relative to the server root, this will correctly map the full path. Very likely from what you stated above, this is true: * $_SERVER['DOCUMENT_ROOT'] == "/var/www/sites/sitename" Dante