如何检查两个文件是否存在 [英] How to check if two files exist

查看:44
本文介绍了如何检查两个文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CodeIgniter的安装应用程序route.php 上,我想检查是否存在两个文件并根据它们进行设置.

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

如果文件存在,则将对其进行升级,否则转到步骤1.

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'] = '';
}

推荐答案

尝试一下:

您需要单独检查文件是否存在.

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'] = '';
}

您可以阅读手册 file_exists .

You can read on the manual, file_exists.

这篇关于如何检查两个文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆