tags:

views:

86

answers:

4

when on "index.php", I do require_once("/all_fns.php").

"all_fns.php" itself requires files with paths relative to all_fns.php (itself).

My question is, should I write the paths on all_fns relative to all_fns.php or to index.php?

This is all very confusing to me and wanted to get it straight.

+3  A: 

They are treated as relative to index.php.

If you need to reference a file relative to the include, use

__DIR__."/relative/file.php";
Pekka
No need for `dirname(__FILE__)` just use `__DIR__`.
Alix Axel
True that. Edited.
Pekka
This worked for me when I wanted a relative path. require_once('../bla.php'); would not work. require_once(\_\_DIR\_\_.'/../bla.php'); works.
Keyo
A: 

in index.php define some directories

define ( 'INCLUDES_DIR', dirname( __FILE__ ) );
define ( 'INCLUDES_DIR2', INCLUDES_DIR . '/some_directory' );

then in all the other files you can use INCLUDES_DIR

include( INCLUDES_DIR1 . 'file.php' );
Galen
+1  A: 

They are relative to the getcwd().

Alix Axel
A: 

Either Use

echo  in_get( "include_path") ;

Or open up your ini file and find out what your ini path is, and put your include file in THAT DIRECTORY (or one of those directories) and release yourself from worrying about absolute/relative include problems forever.

Cups