I am new to programming and learning php on my own. I have two question about the following relative path of a file
$fp = fopen (\"$_SERVER[DOCUMENT_ROOT]/..
..
means the parent directory, so it goes one level up there and into a sibling directory of your document root called orders
.
..
refers to the parent folder.
SO, if $_SERVER[DOCUMENT_ROOT]
happens to be /var/www/
, the following would be equivalent:
"$_SERVER[DOCUMENT_ROOT]/../orders/orders.txt"
"/var/orders.txt"
.. means "go up one directory".
So, if your DOCUMENT_ROOT was:
/usr/docs/document_root
your path works out to:
/usr/docs/document_root/../orders/orders.txt
Since the .. means "go up one", it in fact becomes:
/usr/docs/orders/orders.txt
You can see how it "erases" the "document_root" part.
I like to think that the two dots drop you down by one directory level, which usually refers to the parent folder. Imagine $_SERVER[DOCUMENT_ROOT]
is root
:
root/
index.php // You are here
orders/
orders.txt // You are reading this file