내 스크립트에서 포함 경로를 설정 했으므로 (응용 프로그램의 다른 부분에서도 파일을 포함 할 수 있음) 파일이 있는지 확인하고 포함하십시오.PHP : file_exists()에없는 파일을 포함 할 수 있음
그러나 포함 경로를 설정 한 후에 file_exists()
은 파일이 존재하지 않는다고보고하지만 여전히 동일한 파일을 포함 할 수 있습니다.
<?php
$include_path = realpath('path/to/some/directory');
if(!is_string($include_path) || !is_dir($include_path))
{
return false;
}
set_include_path(
implode(PATH_SEPARATOR, array(
$include_path,
get_include_path()
))
);
// Bootstrap file is located at: "path/to/some/directory/bootstrap.php".
$bootstrap = 'bootstrap.php';
// Returns "bool(true)".
var_dump(file_exists($include_path . '/' . $bootstrap));
// Returns "bool(false)".
var_dump(file_exists($bootstrap));
// This led me to believe that the include path was not being set properly.
// But it is. The next thing is what puzzles me.
require_once $bootstrap;
// Not only are there no errors, but the file is included successfully!
절대 경로를 제공하지 않고 포함 경로와 포함 파일을 편집 할 수 있지만 존재 여부를 확인할 수 없습니다. 존재하지 않는 파일이 호출 될 때마다 내 응용 프로그램이 치명적인 오류를 발생 시키거나 기껏해야 경고 (include_once()
사용)가 될 때마다 이것은 실제로 성가시다.
오류 및 경고를 해제하는 것은 불행히도 옵션이 아닙니다.
누구든지이 문제의 원인을 설명 할 수 있습니까?
감사를 구현하는 가장 간단한 방법입니다, 그게 가장 가능성있는 경우했지만, PHP 매뉴얼에 그것의 어떤 언급을 찾을 수 없습니다 생각했다. 명확히 해 주셔서 감사합니다 :) – zanbaldwin