您的位置:首页 > 编程语言 > PHP开发

php判断文件是否存在并设置默认路径

2013-07-27 14:13 232 查看
/**
 * 判断文件是否存在并设置默认路径
 * @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;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: