17

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]/../orders/orders.txt", 'w');

My questions about the relative path in the code above are that:

  1. What I understand, $_SERVER[DOCUMENT_ROOT] points to the very root directory of the file structure like htdocs, www or public_html on different servers. Please guide if I am understanding it correctly?
  2. What do the two dots mean in the path above?

Thank You

daNullSet
  • 669
  • 2
  • 6
  • 16
  • possible duplicate of [What does a dot mean in a URL path?](http://stackoverflow.com/questions/6008829/what-does-a-dot-mean-in-a-url-path) – nawfal Jan 11 '14 at 03:05

5 Answers5

17

.. means the parent directory, so it goes one level up there and into a sibling directory of your document root called orders.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • The parent directory of the path at that point, i.e. the directory your document root resides in. Will work wonders if your document root is `D:\` of course, but hey, can't have everything. – Joey Aug 22 '12 at 04:58
9

.. 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.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
4

.. 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"
Hamish
  • 22,860
  • 8
  • 53
  • 67
2

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
Blender
  • 289,723
  • 53
  • 439
  • 496
0

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

Mohan
  • 907
  • 5
  • 22
  • 45