我很难尝试理解php中相对路径的过程。我正在使用WAMP工作localhost和我在谷歌等花了几个小时后尝试过的所有东西,只是错误。错误的范围从“无法打开流:没有这样的文件或目录”到堆栈错误。我也尝试过绝对路径,但结果仍然相同。我不知道如何继续,所以真的可以使用一些帮助。我附上了一份我尝试的程序清单,欢迎任何建议。非常感谢
In the admin header file:
<?php require_once('./Connections/connect.php'); ?>
<?php require_once('../../../Connections/connect.php'); ?>
<?php require_once('C:\wamp\www\domain/Connections/connect.php'); ?>
localhost\domain > root > index.php
header.php
footer.php
Connections\connect.php
localhost\domain\admin > index.php
header.php
footer.php
form-inc.php
localhost\domain\admin\cp\users > index.php <--Users control panel in which I need to call
header.php & footer.php from the admin
directory which is where I am having the
problem.
PHP 5.3
WAMP
答案 0 :(得分:1)
尝试这样做可以避免歧义dirname(__FILE__)
OR
如果您使用的是PHP 5.3或更高版本,请使用此 - &gt; __DIR__
。
用法 -
require dirname(__FILE__) . '/../../filename.php';
或 -
require __DIR__ . '/../../../filename.php';
更多来自手册 - http://php.net/manual/en/language.constants.predefined.php