Absolute path & Relative Path

前端 未结 3 1806
太阳男子
太阳男子 2020-11-28 14:49

What\'s the difference between absolute path & relative path when using any web server or Tomcat?

3条回答
  •  醉话见心
    2020-11-28 15:09

    Important to note that relative paths are also subjective.

    ie:

    
    
    /dir/bar.php 
    /foo.php         # prints a 
    /dir/foo.php # prints b 
    /dir/other/   # empty dir
    
    $ pwd 
    >  /
    $ php dir/bar.php 
    >  / + ../foo.php == /foo.php   
    >  prints a 
    $ cd dir 
    $ php bar.php
    >  /dir  + ../foo.php = /foo.php 
    >  prints a
    $ cd other
    $ php ../bar.php 
    > /dir/other + ../foo.php  = /dir/foo.php 
    > prints b
    

    This can create some rather confusing situations, especially if you have many files with releative references and multiple possible places that can act as an "entry point" that controls what the relative path is relative to.

    In such situations, one should compute the absolute path manually based on a fixed known, ie:

    or

    or

提交回复
热议问题