我有以下目录结构,我将所有类放在classes/
中,如下所示,我有header.php
,它们都调用所有文件,并具有所有文件共享的其他重要设置。
现在,如果我以这种方式使用spl_autoload_register()
:
spl_autoload_register(function($class){
include 'classes/'. $class .'.class.php';
});
在inc/header.php
文件中并从我的header.php
文件中调用此index
,然后它在我的本地主机上工作正常,但是当我将所有脚本按原样上传到实时主机时,然后我得到像。的错误。
Warning: include(classes/filehandler.class.php) [function.include]: failed to open stream: No such file or directory in /home/.../public_html/....com/inc/header.php on line 9
Line 9
是spl_autoload_register()
我不明白,这怎么可能发生,并希望任何人都有任何想法。
感谢
答案 0 :(得分:2)
要显示我对评论的意思,请在index.php文件中添加此代码,并从其他文件中删除自动加载器:
spl_autoload_register(function($class){
$classesPath = dirname(__FILE__) . '/classes/';
if (is_file($classFile = $classesPath . $class.'.class.php')) {
include $classFile;
}
});
对于inc / header.php:
spl_autoload_register(function($class){
$classesPath = dirname(__FILE__) . '/../classes/';
if (is_file($classFile = $classesPath . $class.'.class.php')) {
include $classFile;
}
});