Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我如何使require_从上面的目录中获取一个文件?_Php_Apache_Pear_Require Once - Fatal编程技术网

Php 我如何使require_从上面的目录中获取一个文件?

Php 我如何使require_从上面的目录中获取一个文件?,php,apache,pear,require-once,Php,Apache,Pear,Require Once,我正在尝试在一个新服务器上设置一个我不是其原始所有者的站点-在Apache2中,文档根已设置为/var/www/html,这就是我想要作为默认“主页”的index.php所在的位置 在www的其他目录中有许多文件。例如,/common/cachelite/Lite.php也可以在/var/www.php中找到 index.php中的php使用require_引用了一次,如下所示: error_reporting(E_ALL); ini_set('Display_errors','On'); re

我正在尝试在一个新服务器上设置一个我不是其原始所有者的站点-在Apache2中,文档根已设置为/var/www/html,这就是我想要作为默认“主页”的index.php所在的位置

在www的其他目录中有许多文件。例如,/common/cachelite/Lite.php也可以在/var/www.php中找到

index.php中的php使用require_引用了一次,如下所示:

error_reporting(E_ALL);
ini_set('Display_errors','On');
require_once('../common/cachelite/Lite.php');
但抛出以下错误,我已从Apache2 error.log中获取该错误:

PHP Fatal error:  require_once(): Failed opening required '../common/cachelite/Lite.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/index.php on line 4

文件本身肯定在那里,所以有人能为我解释一下这个问题吗?发生了什么事?

我已经遇到过几次这个问题,总是这样解决

$file = dirname(dirname(__file__));
require_once($file ."/common/cachelite/Lite.php");
进一步缩小范围

试试这个 如果在web服务器上执行此操作,而不是在命令行添加
echo __file__ . "\n";
echo dirname(__file__). "\n";
echo dirname(dirname(__file__)). "\n";

我的下一个想法是,文件权限或拼写错误的单词。

您可以将代码更改为

require_once(dirname(__FILE__).'/common/cachelite/Lite.php');
或者你也可以这样做:


检查您试图要求/包括的文件的权限。如果访问/web用户无法读取它们,那么这将解释您遇到的错误。

require
/
include
不受web服务器文档根目录的约束。这是一个仅存在于Web服务器中的概念。PHP只看到文件系统,可以访问其中包含用户ID的任何文件/目录。我也这么想,但事实上,我似乎不需要这个文件,这让我怀疑我自己的知识…把自己放在一个外壳中,打开这个外壳,与PHP脚本的目录相同。然后找出从脚本到包含文件的路径应该是什么。这将是PHP内部需要的路径。是的,但那是。。(上一个目录),然后进入/common/cachelite/Lite.php,所以“../common/cachelite/Lite.php”,这正是我所拥有的。因为某种原因它不起作用。。。我可以通过nano../common/cachelite/Lite.php或使用该路径的cd从index.php目录将nano导入文件中。。。“我是不是遗漏了一些明显的东西?”他说“打开失败”,而不是“没有这样的文件”,所以可能是权限问题。请确保您运行脚本的帐户同时具有对文件夹和实际文件的写入。对于我来说,似乎无法修复此问题。恐怕,与以前相同的错误(行号明显增加到5)不起作用,我最终会出现
PHP致命错误:require_once():无法打开/var/www/html/common/cachelite/Lite.php(include_path=”:/usr/share/php:/usr/share/pear)中第4行的/var/www/html/index.php中所需的“/var/www/html/index.php”(include_path=”)
require_once(dirname(__FILE__).'/common/cachelite/Lite.php');