Forum Moderators: coopster

Message Too Old, No Replies

Including directory and all files in it

         

kkonline

6:12 am on Sep 3, 2007 (gmt 0)

10+ Year Member



I want to include all the files in a particular directory

I know i can write

 include("$_SERVER[DOCUMENT_ROOT]/gb/index.php");
include("$_SERVER[DOCUMENT_ROOT]/gb/post.php");
and so on for each file.

But is there any way i can add all the files inside gb directory at once?
something like include the directory and all it's files.

Habtom

6:18 am on Sep 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the easiest solution is to use glob to find all the files in a specific path with certain format, and loop to include them.

foreach(glob(”include_directory/*.php”) as $include_files) {

require_once($include_files);

}

Habtom

Habtom

6:19 am on Sep 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at Glob [php.net] for the details.

[edited by: Habtom at 6:20 am (utc) on Sep. 3, 2007]

kkonline

4:39 pm on Sep 3, 2007 (gmt 0)

10+ Year Member



great , it worked . thanks