/**
* 判断文件是否存在并设置默认路径
* @param type $currentFilePath //原文件路径
* @param type $defaultFilePath //默认文件路径
* @param type $isRoot //源文件路径是以网站根目录 为绝对路径 是true 否false
* @return type
*/
function defaultFile($currentFilePath, $defaultFilePath) {
$isRoot = preg_match('/^[\/\\\\].*$/', $currentFilePath, $out2); //是否为网站根目录
if ($isRoot) {
$currentFilePath = str_replace('\\', '/', $currentFilePath);
$src = '.' . $currentFilePath;
} else {
$src = $currentFilePath;
}
if (is_file($src)) {
return $currentFilePath;
} else {
return $defaultFilePath;
}
}php判断文件是否存在并设置默认路径
最新推荐文章于 2021-08-09 11:58:28 发布
本文介绍了一个实用的PHP函数,用于判断文件是否存在,并在不存在时返回默认路径。此函数支持多种路径格式,包括网站根目录路径。
5324

被折叠的 条评论
为什么被折叠?



