Path of current PHP script relative to document root

前端 未结 4 2019
一整个雨季
一整个雨季 2021-02-14 09:08

TL;DR: What alternatives to the last code sample on this page are there when trying to use relative links on pages included with PHP\'s include com

4条回答
  •  遇见更好的自我
    2021-02-14 09:38

    Looks like the best way to do this is removing $_SERVER['DOCUMENT_ROOT'] from __DIR__, as I mentioned in the original question.

    define('PROJECT_DIR', preg_replace('/^' . preg_quote($_SERVER['DOCUMENT_ROOT'], '/') . '/', '', __DIR__));
    

    I think I'm just going to do it like that.

提交回复
热议问题