[email protected]:~/php$ ls
a.php data include
[email protected]:~/php$ tree
.
├── a.php
├── data
│ └── d.php
└── include
├── b.php
└── c.php
2 directories, 4 files
[email protected]:~/php$ cat a.php
a.php is including include/b.php ...
<?php include "include/b.php" ?>
[email protected]:~/php$ cat include/b.php
b.php is including c.php and ../data/d.php ...
<?php include "c.php" ?>
<?php include "../data/d.php" ?>
[email protected]:~/php$ cat include/c.php
c.php
[email protected]:~/php$ cat data/d.php
d.php
[email protected]:~/php$ php a.php
a.php is including include/b.php ...
b.php is including c.php and ../data/d.php ...
c.php
PHP Warning: include(../data/d.php): failed to open stream: No
such file or directory in /home/disc/php/include/b.php on line 3
PHP Warning: include(): Failed opening '../data/d.php' for
inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/
disc/php/include/b.php on line 3
[email protected]:~/php$
include "c.php"
은 성공하지만 include "../data/d.php"
은 실패한 이유는 무엇입니까?이 PHP 상대 포함이 실패하는 이유는 무엇입니까?
http://www.php.net/manual/en/function.include.php는 언급 : "경로 가 정의되어있는 경우 - 절대 여부 ( Windows에서 드라이브 문자 또는 \로 시작하거나,/유닉스/리눅스 시스템에서) 또는 현재 디렉토리를 기준으로 (로 시작하는 나.. .) - include_path를 아예 를 무시하는 파일 이름이 ../로 시작하는 경우 예를 들어, 파서 는 요청 된 파일을 찾을 수 상위 디렉토리에서 찾게됩니다 "무엇
부모 디렉토리를..?
을하지만에 c.php 아니다 현재 디렉토리. 현재 디렉토리는'/ disc/php'이고 c.php는'/ disc/php/include'에 있습니다. –
제 질문에, a.php는 호출 된 스크립트이고 모든 경로는 a.php와 관련이 있습니까? –
c.php는 include를 호출하는 파일의 현재 디렉토리에 있습니다. (b.php) – Rufinus