当我运行以下脚本时:
<html>
<head>
<title>Example</title>
</head>
<?php
echo get_include_path(), "\n";
var_dump(is_file('/usr/lib/php/HTTP/OAuth.php'));
?>
<body>
</body>
</html>
我在渲染页面上得到以下输出:
.:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true)
但是,如果我运行此脚本:
<html>
<head>
<title>Example</title>
</head>
<?php
echo get_include_path(), "\n";
var_dump(is_file('/usr/lib/php/HTTP/OAuth.php'));
#### NEW SECTION ####
if (include(''/usr/lib/php/HTTP/OAuth.php'') == 'OK') {
echo 'INCLUDE OK, "\n"';
} else { echo 'INCLUDE FAILED \n' ; }
#### END NEW SECTION ####
?>
<body>
</body>
</html>
我得到以下输出:
.:/php/includes:/usr/lib/php:/usr/lib/php/PEAR bool(true) INCLUDE FAILED \n
如果说文件已存在,为什么包含失败?
如果有帮助,请取消输出:
Darwin 70cd606c7510 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386
感谢您的帮助。
约翰
答案 0 :(得分:3)
您应该阅读Example #4 on the PHP help page:
<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
echo 'OK';
}
// works
if ((include 'vars.php') == 'OK') {
echo 'OK';
}
?>
另外,原始代码中的双引号是拼写错误吗?