Re: include_path and absolute paths in include functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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 8

You 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux