如何检查包含路径下是否存在文件? [英] How to check if a file exists under include path?
本文介绍了如何检查包含路径下是否存在文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以使用 get_include_path()
我想知道在不发出 PHP 错误的情况下检查是否可以包含文件的轻量级方法是什么.我正在使用 Yii 框架,我想在不发出 PHP 错误的情况下进行导入,但我失败了.
I am wondering what is the lightweight way to check if the file can be included without issuing a PHP error. I am using Yii framework and I want to an import without issuing PHP error, but I fail.
推荐答案
在 PHP 5.3.2 之前,您可以拆分路径并在循环中检查每个路径:
Before PHP 5.3.2 you can split the path and check each path in a loop:
$find = 'file.php'; //The file to find
$paths = explode(PATH_SEPARATOR, get_include_path());
$found = false;
foreach($paths as $p) {
$fullname = $p.DIRECTORY_SEPARATOR.$find;
if(is_file($fullname)) {
$found = $fullname;
break;
}
}
//$found now contains the file to be included, or false if not found
这篇关于如何检查包含路径下是否存在文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文