2017-12-12 1 views
2

나는 나의 config.php를을 포함하여 각 페이지에 내 헤더를 삽입하려면 다음을 사용하고 있습니다 :__DIR__을 올바르게 사용 했습니까?

Warning: require_once(/opt/lampp/htdocs/templates/admin/config.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/templates/admin/listArticles.php on line 1

그러나

<?php require_once __DIR__."/config.php"; require_once SITE_ROOT."/templates/include/header.php" ?> 

, 그래서, 나는 다음과 같은 오류를 수신 할 때 referance에 들어,이 config.php를 보이는 것입니다 같은 :

<?php 
 
ini_set("display_errors", true); 
 
date_default_timezone_set("Australia/Sydney"); // http://www.php.net/manual/en/timezones.php 
 
define("DB_DSN", "mysql:host=localhost;dbname=cms"); 
 
define("DB_USERNAME", "username"); 
 
define("DB_PASSWORD", "password"); 
 
define("CLASS_PATH", "classes"); 
 
define("TEMPLATE_PATH", "templates"); 
 
define("HOMEPAGE_NUM_ARTICLES", 5); 
 
define("ADMIN_USERNAME", "admin"); 
 
define("ADMIN_PASSWORD", "mypass"); 
 
define('SITE_ROOT', __DIR__); 
 
require(CLASS_PATH . "/Article.php"); 
 

 

 
function handleException($exception) { 
 
    echo "Sorry, a problem occurred. Please try later."; 
 
    error_log($exception->getMessage()); 
 
} 
 

 
set_exception_handler('handleException'); 
 
?>

SITE_ROOT가 정의되지 않았다는 오류 메시지가 이전에 수신되었다는 것을 언급 할 가치가 있습니다. 그러나 이후 befoer /config.php 디렉토리를 포함시켜이 문제를 해결했습니다.

사이트의 다른 곳에서도 require_once__DIR__ ..을 사용하려고했는데 정상적으로 작동합니다.

오류의 원인은 무엇입니까? 귀하의 오류 메시지

Warning: require_once(/opt/lampp/htdocs/templates/admin/config.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/templates/admin/listArticles.php on line 1

보면

+0

이 라인을 정의하는 곳 define ('SITE_ROOT', __DIR__); ? in which file – samehanwar

+0

그 줄은 위에서 언급 한 config.php의 일부입니다. config.php의 모든 내용을 포함하도록 게시물을 편집합니다. –

답변

0

나는 당신의 config.php를이 템플릿과 같은 경로에 있어야되지 가정합니다. 그것은 상대 경로를 사용할 필요가 있으므로 파일의 실제 위치에 따라 위의 config.php 파일의 실제 위치를 기반으로 같은

<?php require_once __DIR__."/../../config.php"; require_once SITE_ROOT."/templates/include/header.php" ?> 

또는 뭔가를 (나는 이것이 무엇인지 모른다).

이 정보가 도움이되기를 바랍니다.

+0

내 파일의 구조를 살펴본 후에 config.php의 경로에 /../를 추가하여 다음 최상위 폴더를 찾도록 스크립트에 지시하고 있음을 알게되었습니다. (config.php가있는 곳) 고마워! –

+0

내 파일의 구조를 살펴본 후 config.php의 경로에 /../를 추가하여 다음 최상위 폴더를 찾도록 스크립트에 지시하고 있음을 알게되었습니다. (config.php가있는 곳) 고마워! –

+0

문제가되지 않아서 기뻤습니다. :) – mic

관련 문제