I have many functions and classes that I have included in my site. Using stackoverflow, I got a script that automatically includes all the files in a folder and its subfolders: PHP: Automatically include
When testing the script, it always worked, and I never had any problems with it. But recently, when switching from a Windows server to a linux server, there are problems with class extension.
PHP Fatal error: class "AcumulusExportBase" not found in path / functions / classes / Acumulus / AcumulusExportWorkshop.php on line 3, referer: pagesite /? page_id = 346
AcumulusExportWorkshop extends from AcumulusExportBase. All this fully works on Windows, but refuses to work on Linux.
I can fix this by creating include_once 'AcumulusExportBase.php'; but if there is a better solution, it all seems unnecessary and nullifying the work.
The code I use is as follows:
load_folder(dirname(__FILE__));
function load_folder($dir, $ext = '.php') {
if (substr($dir, -1) != '/') { $dir = "$dir/"; }
if($dh = opendir($dir)) {
$files = array();
$inner_files = array();
while($file = readdir($dh)) {
if($file != "." and $file != ".." and $file[0] != '.') {
if(is_dir($dir . $file)) {
$inner_files = load_folder($dir . $file);
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
} else {
array_push($files, $dir . $file);
}
}
}
closedir($dh);
foreach ($files as $file) {
if (is_file($file) and file_exists($file)) {
$lenght = strlen($ext);
if (substr($file, -$lenght) == $ext && $file != 'loader.php') { require_once($file); }
}
}
}
}
Can someone tell me how this is due to the fact that windows have no problems with extension classes and linux? Also, is there a fix for the problem without manually including base classes?
source
share