所以我只是学习PHP。我正在尝试运行我构建的登录脚本,我收到此错误。
Warning: require_once(../../configs/db_config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\test\assets\includes\logininc.php on line 4
Fatal error: require_once(): Failed opening required '../../configs/db_config.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\test\assets\includes\logininc.php on line 4
这是因为此路径不正确吗?
此代码在页面上。
require_once "../../configs/db_config.php";
require_once "../../includes/memberfunc.php";
db_config位于我运行的页面目录下的文件夹中(logininc.php)
更新:这是有问题的代码。它位于index.php
旁边的基目录中<form id="login-form" method="post" action="assets/includes/logininc.php"> <fieldset>
<legend>Login </legend>
<p>Please enter your username and password to access the administrator's panel</p>
<label for="username"> <input type="text" name="username" id="username" />Username: </label> <label for="password"> <input type="password" name="password" id="password" />Password: </label> <label for="submit"> <input type="submit" name="submit" id="submit" value="Login" /> </label> </fieldset> </form>
答案 0 :(得分:0)
答案 1 :(得分:0)
给出(组成)路径/home/sites/example.com/html/logininc.php
,然后
../../configs/db_config.php
将评估为/home/sites/configs/db_config.php
和
../../includes/memberfunc.php
会传播到/home/sites/includes/memberfunc.php
。
如果如你所说,db_config位于logininc.php所在目录下面的文件夹中,那么你需要更像
的东西require('subdir/logininc.php');
答案 2 :(得分:0)
试试这个:
require_once dirname(dirname(dirname(__FILE__))) . "/configs/db_config.php";
根据目录级别调整dirname
的数量。调试路径:
echo dirname(dirname(dirname(__FILE__))) . "/configs/db_config.php";
答案 3 :(得分:0)
错误Failed to open stream
和No such file or directory
表示您正在尝试要求或包含指定目录中不存在的文件。
出现这种情况有几个原因:
您尝试要求的文件不存在
您指定了错误的路径
我希望这可以帮到你!
答案 4 :(得分:0)
其他人指出,你的道路是错的。
.. means you are going back a directory from the current
你提到你是初学者,我建议你在你感到舒服之前总是指定完整的路径
编辑: 如果配置和包含都在资产中,那么它们应该是这样的:
require_once("/test/assets/configs/db_config.php");
require_once("/test/assets/includes/memberfunc.php");
这样你永远不会感到困惑
答案 5 :(得分:0)
对于dubugging,或者确切地找到require_once期望您的文件所在的位置,请使用realpath(),这将为您提供绝对路径。然后,您可以决定如何从那里导航,这意味着添加/删除..
s
echo realpath("../../configs/db_config.php");