Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if two files exist

On my install application routes.php in CodeIgniter I would like to check if two files exist and set them according.

Where, if the files exist then it would be upgraded, else go to step one.

Is there a better and more safer way?

$admin = dirname(FCPATH) . '/admin/config/database.php';
$catalog = dirname(FCPATH) . '/catalog/config/database.php';

if (file_exists($admin, $catalog)) {
    $route['default_controller'] = "upgrade/index";
    $route['404_override'] = '';
} else {
    $route['default_controller'] = "step_1/index";
    $route['404_override'] = '';
}
like image 711
Mr. ED Avatar asked Feb 27 '15 07:02

Mr. ED


1 Answers

Try this:

You need to check the file existence separately.

if (file_exists($admin) && file_exists($catalog)) {
    $route['default_controller'] = "upgrade/index";
    $route['404_override'] = '';
} else {
    $route['default_controller'] = "step_1/index";
    $route['404_override'] = '';
}

You can read on the manual, file_exists.

like image 142
Oli Soproni B. Avatar answered Oct 21 '22 10:10

Oli Soproni B.