PHP 找不到 require_once 的文件,但它在那里?
Posted
技术标签:
【中文标题】PHP 找不到 require_once 的文件,但它在那里?【英文标题】:PHP cannot find file for require_once, but it's there? 【发布时间】:2015-02-27 00:24:24 【问题描述】:这是MyBB中的一个错误,安装后我从索引中得到这个错误:
Warning: require_once(./global.php): failed to open stream: No such file or directory in C:\jws\htdocs\index.php on line 18
Fatal error: require_once(): Failed opening required './global.php' (include_path='.;C:\php\pear') in C:\jws\htdocs\index.php on line 18
顶部附近的索引代码:
require_once './global.php';
require_once MYBB_ROOT.'inc/functions_forumlist.php';
require_once MYBB_ROOT.'inc/class_parser.php';
文件在那里,我检查了文件夹。我没有更改文件中的任何内容。我使用的是 PHP 5.6.4,并且索引文件是从另一个文件中的 require_once 加载的。 这里:
<?php
$_SERVER = array(
"SERVER_PROTOCOL" => "HTTP/1.1","DOCUMENT_ROOT" => "C:/jws/htdocs","REMOTE_ADDR" => "127.0.0.1","REQUEST_URI" => "/","SERVER_SOFTWARE" => "JWS/1.0","argv" => "","REQUEST_TIME" => "Tue, 30 Dec 2014 12:33:14 PST","PHP_SELF" => "/","REMOTE_PORT" => "56601","REQUEST_METHOD" => "GET","SCRIPT_NAME" => "","SERVER_NAME" => "JWS/1.0","PATH_INFO" => "","ORIG_PATH_INFO" => "","argc" => "","GATEWAY_INTERFACE" => "N/I","SERVER_PORT" => "80","SCRIPT_FILENAME" => "C:/jws/htdocs/index.php","HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.5","HTTP_HOST" => "127.0.0.1","QUERY_STRING" => "","REQUEST_TIME_FLOAT" => "1419971594194","HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","HTTP_ACCEPT_ENCODING" => "gzip, deflate","SERVER_ADDR" => "127.0.0.1","HTTP_CONNECTION" => "keep-alive",
);
$_GET = array(
);
$_POST = array(
);
$_COOKIE = array(
);
$_REQUEST = array(
);
require_once 'C:/jws/htdocs/index.php';
?>
【问题讨论】:
全局文件在同一个文件夹的哪里?? @sanojlawrence index.php 和 global.php 在同一个 htdocs 文件夹中。 如果您需要将索引文件放入另一个文件中,则从它所在的位置(包含索引的文件)执行 require 语句 @Rizier123 我正在编写一个自定义网络服务器,我需要运行上面生成的代码,我该如何更改工作目录? 然后像这样替换并运行require_once 'global.php';
【参考方案1】:
用这个替换你的索引代码
require_once 'global.php';
require_once MYBB_ROOT.'inc/functions_forumlist.php';
require_once MYBB_ROOT.'inc/class_parser.php';
【讨论】:
【参考方案2】:我设法使用:
chdir("the path");
更改工作目录,我也遇到了服务器重定向失败的问题。
感谢您的帮助!
【讨论】:
你不应该回答自己的问题 @sanojlawrence 是的,他是/可以!如果他自己想通了,他可以将他的解决方案分享给有同样问题的其他人!他也能接受自己的答案吗! @Rizier123 如果他能回答自己的问题,那么提问有什么用 @sanojlawrence 分享解决方案! (也看看这里,这个人解决了他的问题,2年后回答了!***.com/q/9260717/3933332)另外你可能想阅读帮助中心:***.com/help/self-answer【参考方案3】:顶部附近的index.php代码:
<?PHP
require_once MYBB_ROOT.'/global.php';
require_once MYBB_ROOT.'/inc/functions_forumlist.php';
require_once MYBB_ROOT.'/inc/class_parser.php';
?>
indexTest.php
<?php
define("MYBB_ROOT", __DIR__);
$_SERVER = array(
"SERVER_PROTOCOL" => "HTTP/1.1","DOCUMENT_ROOT" => "C:/jws/htdocs","REMOTE_ADDR" => "127.0.0.1","REQUEST_URI" => "/","SERVER_SOFTWARE" => "JWS/1.0","argv" => "","REQUEST_TIME" => "Tue, 30 Dec 2014 12:33:14 PST","PHP_SELF" => "/","REMOTE_PORT" => "56601","REQUEST_METHOD" => "GET","SCRIPT_NAME" => "","SERVER_NAME" => "JWS/1.0","PATH_INFO" => "","ORIG_PATH_INFO" => "","argc" => "","GATEWAY_INTERFACE" => "N/I","SERVER_PORT" => "80","SCRIPT_FILENAME" => "C:/jws/htdocs/index.php","HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.5","HTTP_HOST" => "127.0.0.1","QUERY_STRING" => "","REQUEST_TIME_FLOAT" => "1419971594194","HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","HTTP_ACCEPT_ENCODING" => "gzip, deflate","SERVER_ADDR" => "127.0.0.1","HTTP_CONNECTION" => "keep-alive",
);
$_GET = array(
);
$_POST = array(
);
$_COOKIE = array(
);
$_REQUEST = array(
);
require_once MYBB_ROOT.'/index.php';
?>
【讨论】:
以上是关于PHP 找不到 require_once 的文件,但它在那里?的主要内容,如果未能解决你的问题,请参考以下文章
有人可以指出为啥我的 require_once() 函数找不到路径吗? php