Get parent directory of running script

后端 未结 13 2070
攒了一身酷
攒了一身酷 2020-11-30 04:20

In PHP, what would be the cleanest way to get the parent directory of the current running script relative to the www root? Assume I have:

$_         


        
13条回答
  •  猫巷女王i
    2020-11-30 05:06

    As of PHP 5.3.0 you can use __DIR__ for this purpose.

    The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__ FILE__).

    See PHP Magic constants.

    C:\www>php --version
    PHP 5.5.6 (cli) (built: Nov 12 2013 11:33:44)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    
    C:\www>php -r "echo __DIR__;"
    C:\www
    

提交回复
热议问题