在php中找到一个4个目录的文件 [英] finding a file in php that is 4 directories up
本文介绍了在php中找到一个4个目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到文件,即使使用多个 ../
查找文件:
I cannot locate the file even when using multiple ../
to find the file:
root -> public -> secure -> lock -> login / "data.php"
panel -> data -> list / "list.php"
我想包括 data.php
与我的 list.php
并尝试执行以下操作来包含数据:
I want to include data.php
with my list.php
and tried doing the following to include the data:
include("../../../../lock/login/data.php");
include("../../../lock/login/data.php");
and also
include("../../lock/login/data.php");
然而,这似乎不起作用,但如果我把它放在$ code > list.php 并执行以下操作,它读取数据就好了:
However, this doesn't seem to work, but if I place it beside list.php
and do the following, it reads the data just fine:
include("data.php");
我的代码做错了什么,什么是更好的方法来执行? >
What am I doing wrong with my code and what is a better way to execute this?
推荐答案
学习使用:
__FILE__; // for your current file path
dirname(__FILE__) or __DIR__; // for your current file parent folder
$_SERVER['DOCUMENT_ROOT']; // for your sites inception folder, your pivotal point
这应该让你的方式。 然后你可以:
This should get you on your way. Then you can:
include __DIR__.'/../file-REALLY-relative-to-directory-of-edit-file.php';
include $_SERVER['DOCUMENT_ROOT'].'/absolute-path-reliable-for-your-site.php';
永远不会相关包含类似 (当前目录可以更改并打破你的世界):
include 'an-unreliable-NOT-REALLY-relative-file.php';
希望它有帮助!
这篇关于在php中找到一个4个目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文