今日まで、そのコードを使用して 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');