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.
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 folderfooin the grandparent directory (ie. the grandparent directory). (I am your father’s, brother’s, nephew’s, cousin’s former roommate)/= file system root directory.