PHP包含类中的文件,错误的路径

时间:2014-07-18 19:57:17

标签: php

我有一个名为client的类,并且我有一个函数,我正在尝试包含/执行php文件,但是当我这样做时,我试图包含的文件中的所有路径都出错了。

班级职能:

public static function SendSSHCommand($ssh_cmd) {
        include('../Core/core_class.php');
        $ssh = new samp_panel();
        $ssh->SendCommand($ssh_cmd);
}

我想获得一个解决方案,如何包含文件,该文件中的所有目录路径都不会出错。

我收到很多错误:

Warning: include(Net/SSH2.php): failed to open stream: No such file or directory in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30

Warning: include(Net/SSH2.php): failed to open stream: No such file or directory in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30

Warning: include(): Failed opening 'Net/SSH2.php' for inclusion (include_path='.:/usr/share/pear:Core/NetModule') in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30

Fatal error: Class 'Net_SSH2' not found in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 366

1 个答案:

答案 0 :(得分:0)

我在运行脚本时总是更改include目录。对我来说,如果我为所有包含的文件设置一个参考点,它就会变得更容易。

http://php.net/manual/en/function.set-include-path.php

将这样的内容放在文件的顶部

set_include_path('/usr/www/2/main');
include('include1.php');
include('subdir_of_include_path/include2.php');

有几种选择,但这是我认为对我的项目有用的选项。这样我强迫并知道我的包含路径是什么。

相关问题