需要帮助解释 PHP 文件

发布于 2024-11-30 10:22:19 字数 836 浏览 0 评论 0原文

我有一个新项目,每个页面的开头都有一些代码。我需要澄清这一系列声明的作用。这是开场白:

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

篱下浅笙歌 2024-12-07 10:22:19

../ 指当前目录的父目录。

../../ 指的是父级的父级。 ETC。

../ refers to the parent directory of the current directory.

../../ refers to the parent of the parent. etc.

吝吻 2024-12-07 10:22:19

这是 ../ 始终引用 父目录../ 越多,您获得的父目录就越多。有了足够的信息,您就可以到达文件系统的根目录(尽管您最好只使用 /)。这并不是实现这一目标的最佳方法。

$dir = str_repeat( '../', $level );

会更明显并且更具可扩展性。更好的选择仍然是拥有一些配置文件,它只需执行以下操作:

// obviously this would be a better constant name.
define( 'PATH_TO_STUFF', dirname( __FILE__ ) ); // use __DIR__ on PHP 5.>=3

额外信息:

  • ./ =当前目录
  • ../ =父目录
  • ./ ../../ = 当前目录的祖父
  • ./../../foo/../ 文件夹 foo 的父目录祖父母目录(即祖父母目录)。 (我是你父亲、兄弟、侄子、表弟的前室友)
  • / = 文件系统根目录。

This is a ../ always refers to parent 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.

$dir = str_repeat( '../', $level );

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:

// obviously this would be a better constant name.
define( 'PATH_TO_STUFF', dirname( __FILE__ ) ); // use __DIR__ on PHP 5.>=3

Bonus info:

  • ./ = current directory
  • ../ = parent directory
  • ./../../ = grandparent of current directory
  • ./../../foo/../ The parent directory of the folder foo 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.
梦魇绽荼蘼 2024-12-07 10:22:19

../ 表示上一个/父目录。因此,如果 $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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文