PHP File Exists


PHP File exists

The file_exists() function can be used to determine if a file exists. Once you know the condition, you can execute the code based on that result.

The code belows checks to see if there is a file called login.inc that is located one directory down from the current directory. If the file exists, it is included. Otherwise, the file login.inc that is located in the same directory is included.

$login_file = '../login.inc';
if (file_exists($login_file)) {
include('../login.inc');
}else{
include('login.inc');
}