PHP absolute path to root

后端 未结 7 1912
轻奢々
轻奢々 2020-11-28 05:44

I can\'t believe PHP doesn\'t have an easy solution for this simple matter. ASP.NET has a ~ sign that takes care of this issue and starts everything from the root level. Her

7条回答
  •  生来不讨喜
    2020-11-28 06:33

    The best way Using dirname(). Because SERVER['DOCUMENT_ROOT'] not working all servers, and also return server running path.

    $root = dirname( __FILE__ );
    
    $root = __DIR__;
    
    $filePath = realpath(dirname(__FILE__));
    
    $rootPath = realpath($_SERVER['DOCUMENT_ROOT']);
    
    $htmlPath = str_replace($root, '', $filePath);
    

提交回复
热议问题