I have the following code snippet:
<?
include("/classes/functions.php");
if(!file_exists("/config.ini")) redirect("/classes/install.php");
else{
//file is processed
}
?>
What this is supposed to do is to read data from a configuration file then use it to connect to a MySQL server. If the configuration file doesn't exist, it redirects to a setup page where the file is created and filled with user-provided data.
Problem is, even though the file doesn't exist, file_exists
returns true anyway, which causes the else
branch to run and fail all over the place.
I tried using $_SERVER['DOCUMENT_ROOT']
in the file path, just in case; no difference.
Documentation: http://php.net/manual/en/function.file-exists.php
Returns TRUE if the file or directory specified by filename exists;
file_exists('/non-existing-file.ini') returns true because path '/' exists
use is_file() instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With