2012-07-22 3 views
0

난에 상주하는 파일이 포함 :PHP는 (올바른 경로를 얻을 수 없다)

<?php include('../sidebar-left-big.php'); //left sidebar, category navigation and ads ?> 

오류가 나는 얻을 :

Warning: include(../sidebar-left-big.php) [function.include]: failed to open stream: No such file or directory in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/template_directorypress/_gallerypage.php on line 9 

Warning: include() [function.include]: Failed opening '../sidebar-left-big.php' for inclusion (include_path='.:') in /Library/WebServer/Documents/wordpress/wp-content/themes/directorypress/template_directorypress/_gallerypage.php on line 9 

내가 제대로 최선을 다하고있어 날 것으로 보인다.

나는 어쩌면 문제는 다른 파일에 포함 통해 그 _gallerypage.php가로드, 그래서 ../ 그 상대가 오류에 이르게 생각했다. 그러나 error는 sidebar-left-big.php의 경로가 어디에 있다고 생각하는지에 대해서는 아무 것도 말하지 않습니다.

답변

1

사용 include dirname(__FILE__).'/../sidebar-left-big.php';

+0

가 올바른 경로가 무엇을 배울 수있는 방법이 있나요 변수의 BASE_PATH의 사용과 TOP_LEVEL_DIR을 확인하기 위해 다른 PHP 파일을 모두이 파일을 참조 할 수 있습니다? dirname을 사용하지 않고 고칠 수 있도록 현재 파일 경로를 어딘가에 인쇄 할 수 있습니까? –

0

이, 자네 말이 맞아. 다른 파일에서 _gallerypage.php을 포함하면

은, 그 자체에 상대적인 경로를 취한다. 그래서 이것을 고쳐야합니다.

가장 좋은 방법은 이러한 어려움을 피할 수 있습니다. 이를 수행하는 방법에는 여러 가지가 있습니다. 마찬가지로, 하나는 상수에 글로벌 루트를 정의하고 모든 것을 모든 곳의 모든 것을 포함합니다. 예를 들어

:

define("BASE" , "/wordpress"); //Define a base directory 

//now whenever you are including and requirng files, include them on the basis of BASE 

require(BASE."/admin/.../some.php"); 
+0

네,하지만 파일에서 호출되는 경우 이해하는 방법은 무엇입니까? bash에서 pwd와 같은 것이 있습니까? –

+0

@SandroDzneladze, 업데이트를 참조하십시오. – Starx

+0

+1은 훌륭한 제안 이었지만 다른 대답을 사용했습니다. –

0

는 다음 코드를 사용하여 PHP 애플리케이션의 루트에 파일로 (예를 들어, config.php 파일)을 저장합니다. 그럼 당신은 가서

<?php 

/** 
* @def (string) DS - Directory separator. 
*/ 
define("DS","/",true); 

/** 
* @def (resource) BASE_PATH - get a base path. 
*/ 
define('BASE_PATH',realpath(dirname(__FILE__)).DS,true); 
define('TOP_LEVEL_DIR', public_base_directory()); 

?> 

<?php 
function public_base_directory() 
{ 
    //get public directory structure eg "/top/second/third" 
    $public_directory = dirname($_SERVER['PHP_SELF']); 
    //place each directory into array 
    $directory_array = explode('/', $public_directory); 
    //get highest or top level in array of directory strings 
    $public_base = max($directory_array); 

    return $public_base; 
} 
?> 
관련 문제