Jerlon Jerlon - 1 year ago 52
PHP Question

"../ path" works rather than "../../"

I was wondering how was that possible.

Technically, I have a head.php file that contains all of the stylesheets and javascripts:



<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>

The file where the bootstrap.min.css is located is 2 folders up and I read somewhere that "../" is moving a step back. So I was wondering why it still works?

Here is the path information:


-includes folders client,css,fonts, & js.

inside the css folder are all the bootstrap css files.

`in the client folder

it includes another folder which is the head.php
Therefore it is 2 folders away for the css folder. How come a single ../ works in locating the path for bootstrap's css?

I asked this question because I think it might cause an error in the future.

Answer Source

If I understand the question correctly, you have the following structure:

  - Client
    - Another folder
      - head.php
  - CSS
    - bootstrap.min.css
    - ...
  - Fonts
  - JS

Any chance that your index.php is actually located in the Client folder, and head.php just gets included in that file?

If so, this works because paths are relative to the main script (not the included script). You can use getcwd() to verify the current directory.