Reputation: 7385
what i'm trying to do is include all the php files in a given directory into the main php file, I'm loading them into an array using Glob()
like so:
// get all php files
$files = glob('*.php');
But when I try to include($files)
I'm getting an error saying it doesn't like arrays, should I use a foreach statement? or is there a better way of doing this?
Upvotes: 2
Views: 98
Reputation: 3137
You'd use a foreach statement, so foreach $files as $file, include($file).
Having said that, I'm not so sure it's a good idea from a security point of view because you're just hoovering up every file in a directory and including it - if a malicious file gets onto your server then glob() leaves you with no way to evaluate whether or not it ought to be there before it's included and parsed.
Upvotes: 2
Reputation: 400992
include()
doesn't accept an array of files -- it only accept one file path as a parameter.
This means you have to loop over that array of files, including one file at a time :
foreach ($files as $file) {
include $file;
}
Upvotes: 0