直到今天,我还在使用那段代码来定位 public_html 来计算要返回的文件夹以导入文件:
$config_path = array_reverse(explode( DIRECTORY_SEPARATOR , getcwd()));
$co = 0;
foreach($config_path as $val){
if($val == "public_html")
break;
$co += 1;
}
$config_path = '';
if($co != 0){
for($i = 0 ; $i < $co ; $i++){
$config_path .= '../';
}
}
然后我就这样使用它:
require_once ($config_path.'core/db-class.php');
那段代码对我很有帮助,尽管我觉得它限制了我,因为当我使用 WAMP 时,我需要拥有 public_html 文件夹等
我正在寻找类似的 php 函数 -getMainRoot()
所以我可以做类似的事情
require_once (getMainRoot().'core/db-class.php');