Yeak
Yeak

Reputation: 2538

Create directory and have all files automatically load everytime

I wanted to set up a config directory where all the files automatically inside this directory will be loaded with every page.

My goal is to put a bunch of functions and defines in there so for example

config/index.php
config/defines.php 

and so and have these files all automatically load every time. Anyone know how i can do that

Upvotes: 0

Views: 101

Answers (2)

IMSoP
IMSoP

Reputation: 97688

Check out the glob() function for a simple way of iterating through files in a directory.

Obviously, you will need to make sure that nothing untrusted can add files to that directory.

Upvotes: 1

Jeroen
Jeroen

Reputation: 13257

$files = glob('config/*.php');
foreach ($files as $file) {
    include $file;
}

Upvotes: 1

Related Questions