Page 1 of 1

Including directory and all files in it

Posted: Mon Sep 03, 2007 1:13 am
by kkonline
I want to include all the files in a particular directory

I know i can write

Code: Select all

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.

Posted: Mon Sep 03, 2007 1:23 am
by s.dot
Sure. Traverse through the directory.

Code: Select all

foreach(glob('/your/directory/*.php') AS $includeFile)
{
    include '/your/directory/' . $includeFile;
}
EDIT| I wouldn't do that though. There's nothing wrong with including files one at a time. At least you know what you're including, and where they're included.

Posted: Mon Sep 03, 2007 3:33 am
by anjanesh
Also check out scandir.