Monday, October 21, 2013

How to Include All PHP Files in Directory - The Easy Way

Ever wonder how to include all php files in directory? I just created PHP snippets that may be useful for you. Here is the code:

The contents of include.php:
<?php
define('MYBASEPATH' , 'inc/');
foreach (glob(MYBASEPATH . '*.php') as $file) {
    if($file != 'index.php') {
        include($file);
    }
}
?>

The code above will include all files in directory inc except index.php. To include all files, simply include include.php file on your script.

<?php
include( 'include.php' );
?>

Enjoy :-)

No comments :

Post a Comment