did you try autoloading? http://php.net/manual/en/language.oop5.autoload.php .. Sorry I dont have permissions to write comments yet..
Updated.. Wesley is right, you will need to have the class name same as file name for autoload to work. I am sorry to assume that you are doing OOP-PHP. If not autoload will not work you will have to do it traditional way
function __autoload($class) {
require ABSPATH. $class .".php";
}
Any file inside the ABSPATH with classname = filename will be automatically loaded.
If you have various paths with different files in them than you will have to create multiple constant variables with path name. And than call them inside autoload with the specific path.
for eg.
class Myprogram{
public function __construct(){
define('ABSPATH', '/home/dalyn/public_html/');
define('ABSPATH_1', '/home/dalyn/public_html/includes');
define('ABSPATH_2', '/home/dalyn/public_html/some_other_folder');
}
function __autoload($class) {
require ABSPATH. $class .".php";
require ABSPATH_1. $class .".php";
require ABSPATH_2. $class .".php";
}
}
//Some other file
$myProg = new Myprogram(); // this will define your constants as well as autoload all the required files
and if you are not using OOP. Than you will have to define different paths as constants and include the files the way you do it now. and if you want to automate this process
this code will be helpful.
if ($handle = opendir(ABSPATH)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
include_once ABSPATH . $entry;
}
}
closedir($handle);
}
this will include all the files present in the folder ABSPATH. You can create a function and call it with whatever path you want to put.
Hope this helps.
Dins