includes with absolute paths
Moderator: General Moderators
includes with absolute paths
I was wondering if there is a way to have absolute paths work in php includes? If so how?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You can use absolute or relative paths with include() and require(). Relative paths are from the directory of the currently executing script. For absolute paths just do:
Code: Select all
include('/the/path/to/my/file.php');
// or tragically
include('C://the/path/to/my/file.php');(#10850)
I've tried but I get these 2 errors:
Code: Select all
Warning: main(/includes/header.php): failed to open stream: No such file or directory in c:\inetpub\wwwroot\mysite\index.php on line 1
Warning: main(): Failed opening '/includes/header.php' for inclusion (include_path='.;c:\php4\pear') in c:\inetpub\wwwroot\mysite\index.php on line 1- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
is /codingtuts/includes
c:\codingtuts\includes ? I doubt it is. Absolute paths means an absolute path within the file system, not relative to your document root. $_SERVER['DOCUMENT_ROOT'] can be used to base a path off it, or figure out what the relative pathing would be.. or alter the include_path (php.ini or dynamic) settings.
set_include_path()/get_include_path()
Some constants you should be aware of: PATH_SEPARATOR and DIRECTORY_SEPARATOR
set_include_path()/get_include_path()
Some constants you should be aware of: PATH_SEPARATOR and DIRECTORY_SEPARATOR