I recently was watching a php video tutorial and the author was showing how to do include a file. He was using XAMPP for the demonstrations and had many files.
When he was showing how to include a file, he mentioned something about putting two dots (..) in front of the file path (/xampp/content/example.html) because of something having to do with where the files were located, assuming that I already had knowledge of this principle. But i don't.
Can anyone explain what is up with having one dot or two dots in front of file paths?
What is the difference between include("/xampp/content/example.html");
, include("./xampp/content/example.html");
, and include("../xampp/content/example.html");
Best How To :
In Linux / Unix environment,
/xampp/content/example.html
means absolute path
./xampp/content/example.html
means relative path of current directory
../xampp/content/example.html
means relative path of parent directory
For the folder structure: /var/www/xampp/content/example3.html
:
If your current folder is /var/www/
...
../
(goes up 1 level) will be /var/
./
(in current level) will be /var/www/
/
will be /
(in Linux, /
means the root of the server, the outermost structure of the filesystem)
../../
(goes up 2 level) will be /
There are 2 types of paths: Relative Path & Absolute Path.
For Relative path, it's relative to your current directory. For absolute path, it's not related to your current directory.