Require_once无法打开流:没有此类文件或目录

时间:2017-01-30 22:42:43

标签: php require-once

我有这个错误:

  

警告:require_once(../ questionTypes / Question.php):无法打开流:第25行/home/u949913003/public_html/includes/essential.php中没有此类文件或目录

     

致命错误:require_once():在/ home / u949913003 / public_html / includes / essential中打开所需的'../questionTypes/Question.php'(include_path ='。:/ opt / php-5.6 / pear')失败第25行的.php

我需要来自New_test.php的essential.php,如下所示:

require_once('../essential.php');

然后在essential.php中,我需要像这样的Question.php:

require_once($config['systemQuestionTypesClassDir'].'Question.php');

$config在config.php中定义:

$config['controller']['a'] = 'Admin';
$config['controller']['e'] = 'Teacher';
$config['controller']['t'] = 'Teacher';
$config['controller']['s'] = 'Student';
$config['controller']['at'] = 'Teacher';
$config['controller']['er'] = 'Teacher';
// System directories
$config['systemControllersDir'] = '../controllers/';
$config['systemQuestionTypesClassDir'] = '../questionTypes/';
$config['systemViewsDir'] = '../views/';
$config['systemLibsDir'] = 'libs/';
$config['systemLangsDir'] = 'langs/';
$config['systemQuestionTypesLibDir'] = $config['systemLibsDir'].question;
$config['systemLangsXml'] = '../resources/languages/';
$config['systemExtraDir'] = = 'extra/';
$config['systemFpdfDir'] = 'fpdf/';
$config['systemPhpGraphLibDir'] = 'phpgraphlib—master/';
$config['systemFileManagerDir'] = 'filemanager/';

我的文件夹结构是:

enter image description here

显然在questionTypes中有Question.php。

我不知道要解决这个问题。

1 个答案:

答案 0 :(得分:1)

当相对路径时,从另一个“include”调用“include”可能会导致问题。如果使用绝对路径,应该不是问题。

您可以使用__DIR__来获取包含写入文件的目录。

我认为这应该有效:

档案:New_test.php

require_once(__DIR__ .'/../essential.php');

档案:essential.php

require_once(__DIR__ .'/../questionTypes/Question.php');