2013-06-24 4 views
0

동일한 디렉토리에 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 디렉토리를 포함 한 후 루트 디렉토리입니다 ......

+0

시도의 include_once 문을 ('..//header.php LIB'); 블로그가 루트의 하위 디렉토리 인 경우 –

+0

경로를 올바르게 전달하지 않는다는 것에주의하십시오 :'include_once (../ 'lib/header.php'); 'include_once ('../ lib/header.php');가되어야합니다. ' –

답변

0

use include_once ('/ lib/header.php');

+0

문제가 지속됩니다 ... – Andrew

0

다음과 같이하십시오 :

$oldcwd = getcwd(); // Save the old working directory 
chdir($_SERVER['DOCUMENT_ROOT']); 
include_once('lib/header.php'); 
chdir($oldcwd);  // Go back to the old working directory 
관련 문제