Get parent directory of running script

后端 未结 13 2086
攒了一身酷
攒了一身酷 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条回答
  •  余生分开走
    2020-11-30 04:52

    Got it myself, it's a bit kludgy but it works:

    substr(dirname($_SERVER['SCRIPT_NAME']), 0, strrpos(dirname($_SERVER['SCRIPT_NAME']), '/') + 1)
    

    So if I have /path/to/folder/index.php, this results in /path/to/.

提交回复
热议问题