죄송합니다. 다시 물어 봤지만 정말 도움이 필요합니다. 나는 같은 디렉토리에 header_sub.php를 포함하고있는 root/lib에 header.php가있다. 일반적으로 직접 코드를 포함 할 수 루트에 파일 :작업 디렉토리를 변경하십시오
include_once('lib/header.php');
하지만 난 않을 것이
include_once(../'lib/header.php'); or
include_once($_SERVER['DOCUMENT_ROOT'].'/lib/header.php'); or
include_once(dirname(__FILE__).'/lib/header.php');
header_sub.php를 사용하는 경우 지금은, 하위 디렉토리/블로그에 example.php이 포함 시키십시오.
header.php와 header_sub.php를 수정하지 않고 포함시킬 수 있습니까?
일부 몸이를 사용하도록 제안 :
$oldcwd = getcwd(); // Save the old working directory
chdir("../"); // Moves up a folder, so from /blog to/
include("header.php"); // Include the file with the working directory as if the header file were being loaded directly, from it's folder
chdir($oldcwd); // Set the working directory back to before
그러나, 내가 볼 수있는 현재의 URL CHDIR(), 여전히이 루트/블로그/lib 디렉토리를 포함 한 후 루트 디렉토리입니다 ......
일관성을 유지하고 이러한 파일에 액세스 할 수있는 공통 경로를 유지해야합니다. 나쁜 디자인을 읽는 해킹을 만드는 것은 해결책이 아닙니다. – DevZer0
은'/ lib'의'/ blog' 하위 디렉토리입니까? – Sergio
안녕 세르지오, 아니, 그들은 루트의 하위 모두입니다 – Andrew