Reputation: 485
When using file_exists(
), it always returns false. But the file actually exists and can be loaded using 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()
. I think the reason is the file_exists()
function always return false.
Upvotes: 0
Views: 5303
Reputation: 1240
Try using Relative Path ex : $_SERVER['DOCUMENT_ROOT']
rather than absolute path
Upvotes: 1
Reputation: 21
This function returns FALSE
for files inaccessible due to safe mode restrictions.
Use the $_SERVER['DOCUMENT_ROOT']
variable in your files path.
Upvotes: 2
Reputation: 566
About file_exists() Php.net states that
This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in 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
Upvotes: 0
Reputation:
$list
in your foreach loop might be set incorrectly. Have you tried $list="class.data.".$list.".php";
?
Upvotes: -1