【问题标题】:Require_once failed to open stream: No such file or directoryRequire_once 无法打开流:没有这样的文件或目录
【发布时间】:2017-06-16 05:58:25
【问题描述】:

我有这个错误:

警告: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') 失败.php 在第 25 行

我需要 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/';

我的文件夹结构是这样的:

显然在 questionTypes 中有 Question.php。

我不知道怎么解决这个问题。

【问题讨论】:

  • 尝试:require_once(dirname( /__FILE/__ ).'/../essential.php'); (注意:FILE 中没有反斜杠)
  • 给出同样的错误

标签: php require-once


【解决方案1】:

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

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

我认为这应该可行:

文件:New_test.php

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

文件:essential.php

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

【讨论】:

  • 问题是我无法更改essential.php 文件,我只能在New_test.php 上工作,因为文件essential.php 与实际工作的站点相关
猜你喜欢
  • 2011-07-04
  • 1970-01-01
  • 2011-05-27
  • 1970-01-01
  • 2015-02-25
  • 2018-01-21
  • 1970-01-01
  • 2016-07-24
  • 1970-01-01
相关资源
最近更新 更多