我正在尝试使用 $_SERVER['DOCUMENT_ROOT'] 变量包含文件。到目前为止,我尝试包含的每个文件都引发了 file-not-found 错误。我以为我只是弄错了目录,所以我尝试包含当前正在运行的脚本。我希望它递归地包含自己,直到它用完堆栈并摔倒。
echo( 'document root = ' . $_SERVER['DOCUMENT_ROOT'] . '<br>' );
echo( 'script name = ' . $_SERVER['SCRIPT_NAME'] . '<br>' );
$szServerPath = $_SERVER['DOCUMENT_ROOT'];
$szIncludePath = $szServerPath . $_SERVER['SCRIPT_NAME'];
echo( "including = " . $szIncludePath );
include( $szIncludePath );
这将产生以下输出:
document root = /var/httpd/htdocs
script name = /CSRC/Damflask/Main/Articles/index.php
including = /var/httpd/htdocs/CSRC/Damflask/Main/Articles/index.php
Warning: include_once(/var/httpd/htdocs/CSRC/Damflask/Main/Articles/index.php) [function.include]: failed to open stream: No such file or directory in /home/www/glmorriL/CSRC/Damflask/Main/Articles/index.php on line 33
看起来它仍然找不到文件。我包含的所有其他文件都显示了相同的错误消息。为什么这行不通?
编辑:似乎差异是由于“别名”。 http://php.net/manual/en/reserved.variables.server.php(参见 Jamie 2 年前的评论)。没有等效的路径吗?看起来 DOCUMENT_ROOT 对我来说完全没用。
谢谢,G