SPL_AUTOLOAD_REGISTERの異なる行動B / N ONLINEおよびLOCALHOST
-
21-12-2019 - |
質問
次のディレクトリ構造を持ち、次のようにclasses/
の中にすべてのクラスを入れて、両方のファイルを呼び出すheader.php
があり、すべてのファイルが共有するその他の重要な設定があります。
今、このようにspl_autoload_register()
を使用している場合:
spl_autoload_register(function($class){
include 'classes/'. $class .'.class.php';
});
.
inc/header.php
ファイルの内部で、このheader.php
ファイルからこのindex
を呼び出してから、LocalHostでうまく機能しますが、すべてのスクリプトをLiveホストにアップロードすると、エラーが発生します。
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()
私はこれが起こるかもしれない方法、そして誰かがまったく考えを持っていることを願っています。
ありがとう
解決
私のコメントで何を意味するのかを示すには、このコードをindex.phpファイルに追加し、他のファイルからオートローダを削除します。
spl_autoload_register(function($class){
$classesPath = dirname(__FILE__) . '/classes/';
if (is_file($classFile = $classesPath . $class.'.class.php')) {
include $classFile;
}
});
.
for inc / header.php:
spl_autoload_register(function($class){
$classesPath = dirname(__FILE__) . '/../classes/';
if (is_file($classFile = $classesPath . $class.'.class.php')) {
include $classFile;
}
});
. 所属していません StackOverflow