Why would I use dirname(__FILE__) in an include or include_once statement?

后端 未结 4 1397
梦谈多话
梦谈多话 2020-12-02 07:31

I have seen this:


Why would I ever need to do th

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 08:00

    If you want code is running on multiple servers with different environments,then we have need to use dirname(FILE) in an include or include_once statement. reason is follows. 1. Do not give absolute path to include files on your server. 2. Dynamically calculate the full path like absolute path.

    Use a combination of dirname(FILE) and subsequent calls to itself until you reach to the home of your '/myfile.php'. Then attach this variable that contains the path to your included files.

提交回复
热议问题