tags:

views:

304

answers:

5

What is set_include_path Relative to, in PHP? Is it the folder where the PHP.exe resides? Is it the webroot? In other words, what folder would set_include_path('/') or set_include_path('.') be referring to?

+1  A: 

The filesystem root and the current directory, respectively.

Ignacio Vazquez-Abrams
By file system root you mean C:\?
Joshua
If your web server et alia are running off C:, sure.
Ignacio Vazquez-Abrams
My web server is running off of X:, which is a shared folder on C: mapped to X:
Joshua
A: 

This is relative to your current script, however, absolute paths can be used. If you start the path name with a / on *nix systems it would be a absolute path.

Tim Cooper
What about on a Windows system?
Joshua
+1  A: 

Relative paths are resolved from the location of the file where include or another function that uses include_path is used in (see description of include_path):

Using a . in the include path allows for relative includes as it means the current directory. However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include.

/ would describe the root of your filesystem and . the current directory.

Gumbo
So what folder would '/' be?
Joshua
@Joshua - Try running a test script - set_include_path('/');echo realpath(get_include_path());
GZipp
Thank you! realpath is exactly what I needed all along!
Joshua
+1  A: 

set_include_path("/") would make the include path be the root folder of the filesystem, and I would take a guess that you'd probably not want to do that as there might be issues with exposing files that you don't want to be seen.

If your php file was /home/users/joebloggs/htmlroot/index.php, then set_include_path(".") would make the include path the directory that the php file is in, ie the "htmlroot" directory.

Rux
A: 

On *nix systems and Windows Apache the / is the root of the file system. While on IIS / points to the root of the vhost.

What I do to handle this is define a LOC constant in my index.php so I never get confused when including files.

define('LOC', dirname(__FILE__));
include(LOC . '/files/file.php');
ajcates