简体   繁体   English

PHP如何在当前文件夹或子文件夹中自动包含PHP文件

[英]PHP How to include PHP file on current folder or sub folder automatically

I have PHP file timezone.php on folder config. 我在文件夹config上有PHP文件timezone.php

Now I want to include it on my PHP file, example in index.php 现在我想将其包含在我的PHP文件中,例如index.php

include("config/timezone.php");

This working OK. 这样工作还可以。

And now example, I have another folder call project . 在现在的示例中,我还有另一个文件夹调用project Inside project have index.php 内部项目有index.php

then I include timezone.php there. 然后在其中包含timezone.php

If I set this: 如果我设置这个:

include("config/timezone.php");

sure, it will not working. 当然,它将无法正常工作。

and the correct way: 正确的方法:

include("../config/timezone.php");

My question: 我的问题:

How to set automatically for including the timezone.php even in sub folder without manually adding ../ ? 如何自动设置为即使在子文件夹中也包含timezone.php,而无需手动添加../

As you can see I set it manual include("../config/timezone.php"); 如您所见,我将其手动设置为include("../config/timezone.php"); , add ../ ,添加../

这是您在寻找http://php.net/manual/zh/function.set-include-path.php吗?

set_include_path( "path/to/config" ) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM