2013-05-28 5 views
1

다음 웹 서버를 호스팅하는 루트 디렉토리에 다음 PHP 스크립트가 있습니다. 정상적으로 작동합니다. 다음과 같이Linux의 LiteSpeed ​​웹 서버에있는 파일의 올바른 경로

Warning: include(/home/name/public_html/folder/config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home/name/public_html/folder/test.php on line 2 

Warning: include() [function.include]: Failed opening '/home/name/public_html/folder/config/config.inc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/name/public_html/folder/test.php on line 2 

Warning: require_once(/home/name/public_html/folder/init.php) [function.require-once]: failed to open stream: No such file or directory in /home/name/public_html/folder/test.php on line 3 

Fatal error: require_once() [function.require]: Failed opening required '/home/name/public_html/folder/init.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/name/public_html/folder/test.php on line 3 

내가 경로를 변경해야 : : 내 웹 루트에 새 폴더에 스크립트를 이동

<?php 
include(dirname(__FILE__).'/config/config.inc.php'); 
require_once(dirname(__FILE__).'/init.php'); 

는, 즉 public_html/myfolder 스크립트는 다음과 같은 오류를 제공

<?php 
include(dirname(__FILE__).'/../config/config.inc.php'); 
require_once(dirname(__FILE__).'/../init.php'); 

맞습니까?

+0

나는 스스로 시도하는 것이 더 쉽습니다. 어쨌든, 필요한 파일은 어디에 있습니까? 무언가를 포함 시키면 포함 된 파일이 실제로 거기에 있는지 확인하면됩니다. –

+0

작동하지만 올바른지 확인하고 싶습니다. 파일은 다음과 같습니다 :'public_html/config/config.inc.php'와 'public_html/init.php' – triwo

+0

'echo dirname (__ FILE __);'출력은 무엇입니까? –

답변

0

엄밀히 말하면, 스크립트 (include 행을 포함하는 스크립트) 만 "public_html/folder"로 옮겼다 고합니다. 그런 식으로 dirname(__FILE__)은 "folder"디렉토리를 포함하여 전체 경로를 포함합니다. 이제 "config"디렉토리에 도달 할 수 있도록 디렉토리 트리에서 한 단계 올라야합니다. 설명은 다음과 같습니다 전에

가 있었다 :

/home/name/public_html/config/config.inc.php 
/home/name/public_html/init.php 

그래서 파일 dirname(__FILE)에서 경로를 사용하여 파일에 액세스 관리

/home/name/public_html/test.php 

. 하지만 지금은 test.php는 디렉토리 "폴더"movedto있다 :

/home/name/public_html/folder/test.php 

따라서, dirname(__FILE__)는 "폴더"디렉토리의 포괄적 인 경로를 반환해야합니다. 그러나 포함 할 필요가있는 파일은 "이전"디렉토리에 있으므로, 포함 된 경로에 ../을 추가해야합니다. 즉, 해당 파일을 abreoreach하려면 :)

+0

루트 디렉토리/public_html :'/ home/name/public_html'과 public_html/folder :'/ home/name/public_html/folder'에서'echo dirname (__ FILE __); 그래서 위에서 언급 한 경로를 사용해야한다 :'include (dirname (__ FILE __). '../config/config.inc.php');'require_once (__ FILE __). '../init.php '); – triwo

+0

물론, 나는 대답에 대해 이것에 대한 설명을했다. 명확하지 않은 경우 알려주십시오. –

+0

'../' **를 ** 앞에 슬래시를 넣거나 ** 슬래시 (즉, 어느 것이 옳은가, Nr 1) 또는 Nr 2)를 추가 하시겠습니까? 1)'require_once (dirname (__ FILE __). '../init.php');'2)'require_once (디렉토리 이름 (__ FILE __). '/ ../init.php');' – triwo