したがって、このディレクトリ構造を調べます
- /include_one.php
- /include_two.php
- /directory/main_file.php
私が/directory/main_file.phpにいてinclude('../include_one.php');
、include_one.php内を呼び出して、 include_two.phpをインクルードするとします。電話する必要がありますinclude('include_two.php);
かinclude('../include_two.php');
?
だから私の質問は:ファイルをインクルードするとき、「相対インクルードパス」はインクルードされたファイルにシフトされますか、それともメインのインクルードファイルに残りますか?
最善の代替策は、root_pathを含むconfig.phpを使用することですが、この段階ではこれは不可能です。
更新:
だから、ここに私のテストがあるので、誰が正しいのかわかりません
ディレクトリ構造
/include.php
/start/start.php
/folder1/includeone.php
/folder1/folder2/includetwo.php
これが各ファイルの内容です
start.php
<?php
echo 'including ../include.php<br />';
include('../include.php');
?>
include.php
<?php
echo 'including folder1/includeone.php<br />';
include('folder1/includeone.php');
?>
includeone.php
<?php
echo 'including folder2/includetwo.php<br />';
include('folder2/includetwo.php');
?>
includetwo.php
<?php
echo 'done<br />';
?>
出力は
../include.php
を含むfolder1/includeone.php
を含むfolder2 /includetwo.phpを含む
完了