Page 1 of 1

How to use the Include statement ?

Posted: Wed Jun 27, 2007 5:25 pm
by l9pt5
Suppose I've three directories anh I have an include file called "inc.php", how would I use this file in my scripts that locate in other directories?

/dir1
/dir1/dir2
/dir1/include/inc.php

How would I use the above include file "inc.php" in "/dir1/dir2" script files?
How would I use the above include file "inc.php" in "/dir1" script files?

I tried different ways, but somehow it doesn't seem to be working. please post some tips. Thanks... :?

Re: How to use the Include statement ?

Posted: Wed Jun 27, 2007 5:33 pm
by Christopher

Code: Select all

include 'dir1/inc.php';
include 'dir1/dir2/inc.php';

Posted: Wed Jun 27, 2007 11:00 pm
by Ambush Commander

Re: How to use the Include statement ?

Posted: Thu Jun 28, 2007 4:23 am
by stereofrog
arborint wrote:

Code: Select all

include 'dir1/inc.php';
include 'dir1/dir2/inc.php';
This will use include_path, which may or may not be desired. To avoid confusions, it's safer to use absolute paths:

Code: Select all

include dirname(__FILE__) . '/dir1/inc.php';

Posted: Thu Jun 28, 2007 10:27 am
by l9pt5
I think I didn't make my post clear, I only have one "inc.php" file in "/dir1/include" directory, but have many different scripts that are using it. These scripts that using the include file could be in any directory. Thanks...

Posted: Thu Jun 28, 2007 10:40 am
by Ambush Commander
Then either set include_path or use absolute paths.