php需要相对路径

php需要相对路径,php,relative-path,include-path,Php,Relative Path,Include Path,当我在索引页中需要任何PHP文件时,我看到一个错误: 我的配置文件: define( "APP_ROOT", realpath( dirname( __FILE__ ) ).'/' ); 我的包含/要求文件放置: localhost/test/includes/ 失败代码和错误: require_once(APP_ROOT .'includes/test1.php'); require_once(APP_ROOT .'includes/test2.php'); fail

当我在索引页中需要任何PHP文件时,我看到一个错误:

我的配置文件:

define( "APP_ROOT", realpath( dirname( __FILE__ ) ).'/' );
我的包含/要求文件放置:

localhost/test/includes/
失败代码和错误:

require_once(APP_ROOT .'includes/test1.php');
require_once(APP_ROOT .'includes/test2.php');

failed to open stream: No such file or directory in C:\xampp\htdocs\test\includes\test.php on line 38

我有什么问题?如何解决任何相对路径的问题。

看起来您的文件是从/test/includes调用的,所以APP\u路径是C:\xampp\htdocs\test\includes\,所以您试图要求C:\xampp\htdocs\test\includes\includes/test1.php等等

回显应用程序路径并查看它打印的内容


最好是使所有包含都相互关联,然后只需玩游戏,从索引中导入单个common.php文件。php

看起来您的文件是从/test/includes调用的,因此应用程序路径为C:\xampp\htdocs\test\includes\,因此,您试图要求C:\xampp\htdocs\test\includes\includes/test1.php等等

回显应用程序路径并查看它打印的内容


您最好将所有包含项都设置为相互关联,然后只需玩从index.php导入单个common.php文件的游戏

Maybe
realpath(dirname(\uu DIR\uuu))
Maybe
realpath(dirname(\uu DIR\uu))

尝试打印出
APP\u ROOT.'includes/test1.php'
以检查目录是否正确我认为此处生成的错误表单。。。。第38行的
上有什么?第38行可能是包含行,因为错误是找不到文件。请尝试打印出
APP_ROOT.'includes/test1.php'
以检查目录是否正确。我不认为此处生成的错误形式。。。。第38行的
上有什么?第38行可能是包含行,因为错误是找不到文件,所以您可能需要包含app_roottest/includes/test1.php'等等,您可能需要包含app_roottest/includes/test1.php'等等