PHP Dynamic include based on current file path

前端 未结 4 2054
北海茫月
北海茫月 2021-02-04 09:59

I want to find a method to include some files based on the current file path.. for example:

I have \"website.com/templates/name1/index.php\", this \"index.php should be

4条回答
  •  被撕碎了的回忆
    2021-02-04 10:28

    Why not do it in the simple way:

    dirname(__FILE__); //Current working directory
    dirname(dirname(__FILE__)); //Get path to current working directory
    

    And then finally

    $include_path = $dir_path . 'file_to_include.php';
    include $include_path;
    

提交回复
热议问题