PHP包含不起作用

Stu*_*rts 0 php debian

我的文件在http://www.example.com//home/www/example.com/wwwDebian的挤压运行.

/home/www/example.com/
    www/
         index.php
    php/
         include_me.php
Run Code Online (Sandbox Code Playgroud)

在php.ini中我已取消注释并更改为:

include_path =".:/home/www/example.com"
Run Code Online (Sandbox Code Playgroud)

在www中的脚本index.php中,我有require_once("/php/include_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
Run Code Online (Sandbox Code Playgroud)

如您所见,include-path根据错误正确设置.但如果我这样做require_once("../php/include_me.php");,它就有效.因此,include-path必须出错.

有谁知道我能做些什么来解决它?

Mih*_*ncu 7

php/
Run Code Online (Sandbox Code Playgroud)

是一个相对路径,并使用当前目录作为起点

./php/
Run Code Online (Sandbox Code Playgroud)

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

/php/
Run Code Online (Sandbox Code Playgroud)

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

  • `include_path()`用于指定相对包含的搜索路径.所以如果你的路径中有`/ var/www/project/libs /:.`,那么包括`mylib/hello.php`也会检查`/ var/www/project/libs/mylib/hello.php`作为当前文件夹(`./ mylib/hello.php`). (2认同)