[英]Why does file_exists always return false?
When using file_exists(
), it always returns false. 使用
file_exists(
)时,它总是返回false。 But the file actually exists and can be loaded using require
. 但该文件实际存在,可以使用
require
加载。 This is my code: 这是我的代码:
// Creating dependency lists.
$data_dependency = array("mysql", "oracle", "postgresql", "sqlite", "access");
// Calling the dependecny files.
foreach ($data_dependency as $list) {
$list = "class.data.$list.php";
_system::debug("Calling required class $list ...");
if (file_exists($list)) {
include($list);
_system::debug("Calling $list was successfull.");
} else {
_system::debug("Calling $list was failed. Now we close the system load.");
exit("Calling $list was failed. Now we close the system load.");
}
}
When I load the page, the page always exit()
. 当我加载页面时,页面总是
exit()
。 I think the reason is the file_exists()
function always return false. 我认为原因是
file_exists()
函数总是返回false。
This function returns FALSE
for files inaccessible due to safe mode restrictions. 对于因安全模式限制而无法访问的文件,此函数返回
FALSE
。
Use the $_SERVER['DOCUMENT_ROOT']
variable in your files path. 在文件路径中使用
$_SERVER['DOCUMENT_ROOT']
变量。
尝试使用相对路径ex : $_SERVER['DOCUMENT_ROOT']
而不是绝对路径
About file_exists() Php.net states that 关于file_exists() Php.net说明了这一点
This function returns FALSE for files inaccessible due to safe mode restrictions. 对于因安全模式限制而无法访问的文件,此函数返回FALSE。 However these files still can be included if they are located in safe_mode_include_dir.
但是,如果这些文件位于safe_mode_include_dir中,则仍可以包含这些文件。
This could explain the fact the the inclusion works and the existance check doesn't. 这可以解释包含工作和存在检查没有的事实。
http://www.php.net/manual/en/function.file-exists.php http://www.php.net/manual/en/function.file-exists.php
$list
in your foreach loop might be set incorrectly. 您的foreach循环中的
$list
可能设置不正确。 Have you tried $list="class.data.".$list.".php";
你试过
$list="class.data.".$list.".php";
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.