Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require all files in a folder

Tags:

php

Is there an easy way to programmatically require all files in a folder?

like image 748
never_had_a_name Avatar asked Apr 22 '10 15:04

never_had_a_name


2 Answers

Probably only by doing something like this:

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

It might be more efficient to use opendir() and readdir() than glob().

like image 68
Tom Haigh Avatar answered Sep 21 '22 23:09

Tom Haigh


No short way of doing it, you'll need to implement it in PHP. Something like this should suffice:

foreach (scandir(dirname(__FILE__)) as $filename) {     $path = dirname(__FILE__) . '/' . $filename;     if (is_file($path)) {         require $path;     } } 
like image 33
soulmerge Avatar answered Sep 20 '22 23:09

soulmerge