PHP: let a file return its own directory

后端 未结 4 2155
盖世英雄少女心
盖世英雄少女心 2021-01-25 19:06

I am having trouble finding the rigth directory on my online server. is there a function that returns the folder the file is stored in?

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 19:39

    The dirname() function will return the directory portion of a path. For example, dirname('foo/bar/baz.php') will return foo/bar.

    This is often used in conjunction with the __FILE__ magic constant for versions of PHP that do not support the __DIR__ magic constant (versions 5.2.x and below):

    require_once dirname(__FILE__) . '/../classes/Class.php';
    

提交回复
热议问题