This article's purpose is to explain what is a Relative, and what is an Absolute File Path.
First, though, we need to specify what is path.
What is a path?
A path is a sequence of directory names, usually leading to a file or directory.
A typical path in Windows looks like:
C:\Documents and Settings\Christopher\My Documents\My Pictures\funny.jpg
A typical path in Linux looks like:
Noted the two basic differences between Windows and Linux paths?
- A Windows path usually starts with a Drive letter like C: , while in Linux, the root directory of the system is symbolized using a slash (/)
- Windows paths use backslashes (\) while Linux paths use slashes (/)
What is NOT a path?
Many people mistake URLs for paths. It's true that they look alike with Linux paths, but there is a main difference.
The URLs are used for accessing a page from the net, while the paths are usually used for accessing files, within a computer, or LAN.
What is an absolute path?
An absolute path is a path that starts right from the root of your computer file system.
In Windows, that means the inclusion of the drive letter (like C:) and in Linux, that means the inclusion of the root slash (/)
The two paths shown earlier, are both absolute paths.
What is a relative path?
A relative path, is a path starting from the Current Directory of your program. In our case, which is PHP, the Current Directory is usually the directory containing the file executed. (Correct me if I'm wrong)
So, if we're on Windows, and the Current Directory is C:\Documents and Settings\Christopher\ , then to access the same file mentioned before, in the absolute path, we should only write My Documents\My Pictures\funny.jpg .
In Linux, with the Current Directory being /var/home/Christopher/ we only need to write documents/pictures/funny.jpg to access the file.
For Joomla! , we have the privilege to know, that almost everything is executed through the index.php file in the root directory of our site.
So, in our case, which we usually don't know the whole path above the root directory of our site, we use relative paths.
For example, to write a file in the root directory of our site, we only write the desired filename.
But if we would like to place a file like the Mailing List file, for example, in the NS Pro module's directory, we would write this as the path:
For more information on file paths, do not hesitate to contact me.