Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diference between /../*.php and *.php

So I had this trouble with a PHP code that I solved, but I don't really know how it works.

I tried to add this to every single file

<?php include '/nav.php'; ?>

So I can only have one file to edit the navbar instead of the whole php files.

The problem came up when I added that code to the files of another folder (ie. /general/vision.php) and I got an error (file not found). I though it was because I only hav the 'nav.php' file on the root of the site.

So, just for fun, I changed the sentence of the /general/vision.php file to

<?php include '../nav.php'; ?>

And it worked. I didn't changed the nav.php from the root, and it worked.

I'm glad it did, but I don't know why. How does that /../ works? Is that listed on the PHP documentation?

like image 416
Axel Mtz Avatar asked Sep 09 '13 17:09

Axel Mtz


2 Answers

.. is OS nomenclature for "up a directory." It's nothing PHP specific.

Take a look at the concept of Relative paths.. might shed some light. Relative paths vs Absolute paths.

like image 55
ddavison Avatar answered Nov 11 '22 06:11

ddavison


.. refers to the parent directory. This is pretty standard for all operating systems.

like image 4
Daniel A. White Avatar answered Nov 11 '22 07:11

Daniel A. White