PHP include file in webroot from file outside webroot

后端 未结 5 1356
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 20:02

I have a php file outside my webroot in which I want to include a file that is inside the webroot.

folder outside webroot
- > php file in which

5条回答
  •  余生分开走
    2020-12-03 20:25

    Have this in a common file, shared by all your php sources outside the webroot:

    And then use the following to include files.

    If the location of your webroot changes, you will only have to change that once in your code base.

    You can configure php to automatically prepend a given file to all your scripts, by setting the auto_prepend_file directive. That file could for instance contain the PATH_TO_WEBROOT constant, or require_once the file which contains it. This setting can be done on a per domain or per host basis (see the ini sections documentation).

    Also, consider using the autoload feature if you are using classes extensively.

提交回复
热议问题