Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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不包括';它不能正常工作_Php_Debian - Fatal编程技术网

PHP不包括';它不能正常工作

PHP不包括';它不能正常工作,php,debian,Php,Debian,我在http://www.example.com//home/www/example.com/www中的在Debian上运行 /home/www/example.com/ www/ index.php php/ include_me.php 在php.ini中,我已取消注释并更改为: include_path =".:/home/www/example.com" 在www的脚本index.php中,我有require\u once(“/ph

我在
http://www.example.com/
/home/www/example.com/www
中的
在Debian上运行

/home/www/example.com/
    www/
         index.php
    php/
         include_me.php
在php.ini中,我已取消注释并更改为:

include_path =".:/home/www/example.com"
在www的脚本index.php中,我有
require\u once(“/php/include\u me.php”)
。我从PHP获得的输出是:

Warning: require_once(/php/include_me.php) [function.require-once]: failed to open stream: No such file or directory in /home/www/example.com/www/index.php on line 2

Fatal error: require_once() [function.require]: Failed opening required '/php/include_me.php' (include_path='.:/home/www/example.com') in /home/www/example.com/www/index.php on line 2
如您所见,include路径是根据错误正确设置的。但是如果我确实
需要一次(“../php/include_me.php”),它可以工作。因此,include路径肯定有问题

有人知道我能做些什么来修复它吗

php/
是相对路径,使用当前目录作为起点

./php/
/php/
是相对路径,并显式声明当前目录()作为起点

./php/
/php/
是一个相对路径,这意味着它的起点是顶级目录(根目录/

,来自以下文档:

如果定义了路径-无论是绝对路径(在Windows或/在Unix/Linux系统上以驱动器号或\开头)还是相对于当前目录(以.or..开头)-include_路径都将被完全忽略。例如,如果文件名以../开头,解析器将在父目录中查找请求的文件


由于您在本例中指定的是绝对路径,因此会忽略包含路径。

require once上的开始斜杠将从根搜索。。。尝试:

require_once('php/include_me.php');

这是试图在您的文件系统上,而不是在您的web目录上,从字面上获取文件at/php

require_once("/php/include_me.php");

我同意Mihai Stancu的观点,但我想补充一点,使用dirname(_文件__)可能是更好的做法,这样当目录移动时,代码就不会中断。这类似于绝对路径,但允许您将其视为本地路径。

require\u once(“/php/include\u me.php”)的解释:

您为“/home/www/example.com/”设置了include路径,但这是/home/www的子目录。您的require_once正在查找/php/include_me.php

/
home/
    www/
        example.com/
              php/
              www/
php/
    include_me.php
在require调用中有一个前面的/,它正在查找/php/include_me.php。要查找/home/www/example.com/php/include_me.php,您需要:

require_once('php/include_me.php');
您还可以将包含路径设置为:

include_path =".:/home/www/example.com/:/home/www/example.com/www/:/home/www/example.com/php/"

确切地因此,当使用/php/时,它实际上应该包含from include\u路径/php/但是看起来好像没有。“/php”将包含在归档系统根目录下的文件夹中,我想这不是您想要的。
include\u path()
用于指定相对包含的搜索路径。因此,如果您的路径中有
/var/www/project/libs/:.
,那么include
mylib/hello.php
将检查
/var/www/project/libs/mylib/hello.php
以及当前文件夹(
/mylib/hello.php
)。使用include路径组成相对路径,完整路径也会被检查。。。满分,-1“不能正常工作”对你的问题来说是个坏名字。计算机做你告诉他们做的事,而不是你想让他们做的事。啊哈,所以如果你使用php/include_me.php,它会在www文件夹中查找文件,如果找不到,它会在include_路径中搜索。php/include\u me.php?无论是
php/include\u me.php
还是
/php/include\u me.php
都应该可以正常工作(这意味着他们应该使用include路径,直到找到文件为止)。
dirname(\uu file\uu)
指的是当前文件所在的目录,与当前脚本启动的目录不同(例如:index.php包括class/doohickie.php,在类
dirname(\uuu文件\uuu)='/var/www/class'
中,而
'.='/var/www')
中,它取决于预期/预期的结果