需要帮助解释 PHP 文件
我有一个新项目,每个页面的开头都有一些代码。我需要澄清这一系列声明的作用。这是开场白:
<?php
session_start();
$levels = 1;
include("../Connections/main.php");
include("../queries.php");
我理解所有内容,除了 $levels = 1;
与 include("../queries.php");
的关系
。 include("../queries.php");
我看到它以以下语句开头:
<?php
switch($levels) {
case 1:
$dir = "../";
break;
case 2:
$dir = "../../";
break;
case 3:
$dir = "../../../";
break;
case 4:
$dir = "../../../../";
break;
case 5:
$dir = "../../../../../";
break;
}
function db_info($table,$where,$value,$info,$dir) {
//the functions just continue from there
这是我不遵循的部分。据我所知,有一个 switch 语句根据代码第一位中定义的 $levels
的值提供了 $dir
的几种情况。但是 $dir
值的这些不同输出如何转换?这是您以前见过或使用过的东西吗? ../
代表什么?谢谢。
I have a new project that has a bit of code at the beginning of every page. I am in need of some clarification on what this series of statements do. Here is the opening call:
<?php
session_start();
$levels = 1;
include("../Connections/main.php");
include("../queries.php");
I understand all of it except how $levels = 1;
relates to include("../queries.php");
When I look at include("../queries.php");
I see that it begins with the following statement:
<?php
switch($levels) {
case 1:
$dir = "../";
break;
case 2:
$dir = "../../";
break;
case 3:
$dir = "../../../";
break;
case 4:
$dir = "../../../../";
break;
case 5:
$dir = "../../../../../";
break;
}
function db_info($table,$where,$value,$info,$dir) {
//the functions just continue from there
This is the portion that I don't follow. I understand that there is a switch statement that offers several cases for $dir
based upon the value of $levels
which was defined in the first bit of code. But how do these different outputs for the $dir
value translate? Is this something you've seen or used before? What does the ../
stand for? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
../
指当前目录的父目录。../../
指的是父级的父级。 ETC。../
refers to the parent directory of the current directory.../../
refers to the parent of the parent. etc.这是
../
始终引用父目录
,../
越多,您获得的父目录就越多。有了足够的信息,您就可以到达文件系统的根目录(尽管您最好只使用/
)。这并不是实现这一目标的最佳方法。会更明显并且更具可扩展性。更好的选择仍然是拥有一些配置文件,它只需执行以下操作:
额外信息:
./
=当前目录../
=父目录./ ../../
= 当前目录的祖父./../../foo/../
文件夹foo
的父目录祖父母目录(即祖父母目录)。 (我是你父亲、兄弟、侄子、表弟的前室友)/
= 文件系统根目录。This is a
../
always refers toparent directory
, the more../
the more parents you get. With enough you can get to the root of the file system (though you're better off just using/
). This isn't exactly the best way to accomplish this.Would be more obvious and it would be more extensible. A better option still would be to have some config file which simply did something like:
Bonus info:
./
= current directory../
= parent directory./../../
= grandparent of current directory./../../foo/../
The parent directory of the folderfoo
in the grandparent directory (ie. the grandparent directory). (I am your father's, brother's, nephew's, cousin's former roommate)/
= file system root directory.../
表示上一个/父目录。因此,如果$level == 1
,则$dir
将等于../
。其他东西必须使用 dir 来构造路径。
The
../
means previous/parent directory. So if$level == 1
, then$dir
will equal../
.Something else must use dir to construct a path.