What do the dots mean in relative file path?

前端 未结 4 613
面向向阳花
面向向阳花 2020-12-17 15:44

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


        
相关标签:
4条回答
  • 2020-12-17 16:06

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

    0 讨论(0)
  • 2020-12-17 16:12

    .. 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"
    
    0 讨论(0)
  • 2020-12-17 16:15

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

    0 讨论(0)
  • 2020-12-17 16:27

    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
    
    0 讨论(0)
提交回复
热议问题