2013-03-23 351 views
0

使用file_exists(时),它总是返回false。但该文件实际存在,可以使用require加载。这是我的代码:为什么file_exists总是返回false?

// 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."); 
    } 
} 

当我加载页面时,页面总是exit()。我认为原因是file_exists()函数总是返回false。

+1

尝试使用绝对路径。 – C9HDN 2013-03-23 14:09:00

+6

你说文件单数存在,但你正在寻找5,如果任何一个不存在它将退出 – Crisp 2013-03-23 14:09:05

+0

@Calum - 我试图使用绝对路径,但仍然是错误的。 – 2013-03-23 14:25:58

回答

-1

$list在您的foreach循环中可能设置不正确。你有没有试过$list="class.data.".$list.".php";

+3

所以你知道,PHP用双引号评估变量。所以他的'$ list'的构建是正确的 – UnholyRanger 2013-03-23 14:23:40

+0

'$ list'是正确的。当我回显'$ list'时,输出将会是“class.data.mysql.php”。 – 2013-03-23 14:31:25

0

关于file_exists() Php.net指出

该功能因为安全模式的限制将返回FALSE为不可访问的文件。但是,如果这些文件位于safe_mode_include_dir中,它们仍然可以包含在内。

这可以解释包含工作和存在检查没有的事实。

http://www.php.net/manual/en/function.file-exists.php

+1

我认为'safe_mode'已从PHP 5.4.0中移除。我使用PHP 5.4.7。 – 2013-03-23 14:35:01

2

该函数返回FALSE对由于安全模式的限制无法访问的文件。

在文件路径中使用$_SERVER['DOCUMENT_ROOT']变量。

1

尝试使用相对路径ex : $_SERVER['DOCUMENT_ROOT']而不是绝对路径

相关问题