relative path in require_once doesn't work

后端 未结 4 1759
时光取名叫无心
时光取名叫无心 2020-11-29 18:57

I have the following structure

otsg
 > class
   > authentication.php
   > database.php
   > user.php
 > include
   > config.inc.php
   >         


        
4条回答
  •  独厮守ぢ
    2020-11-29 19:38

    Use

    __DIR__
    

    to get the current path of the script and this should fix your problem.

    So:

    require_once(__DIR__.'/../class/user.php');
    

    This will prevent cases where you can run a PHP script from a different folder and therefore the relatives paths will not work.

    Edit: slash problem fixed

提交回复
热议问题