zoukankan      html  css  js  c++  java
  • PHP 判断远程文件是否存在

    /**
     * 判断远程文件是否存在
     * @param $url string 远程文件地址URL
     * @return array|bool
     */
    function originFileExists($url){
        //设置上下文流的参数
        stream_context_set_default(
            array(
                'http' => array(
                    'timeout' => 5,
                )
            )
        );
        //获取HTTP请求中发送的服务器信息
        //format 如果将可选的 format 参数设为 1,则 get_headers() 会解析相应的信息并设定数组的键名
        $header = get_headers($url,1);
        //查找并返回字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE
        if(strpos($header[0],'200')){
            return true;
        }
        if(strpos($header[0],'404')){
            return false;
        }
        if (strpos($header[0],'301') || strpos($header[0],'302')) {
            if(is_array($header['Location'])) {
                $redirectUrl = $header['Location'][count($header['Location'])-1];
            }else{
                $redirectUrl = $header['Location'];
            }
            return fileExists($redirectUrl);
        }
    }
    
  • 相关阅读:
    MongoDB的简单操作
    MongoDB下载安装
    enctype="multipart/form-data" form表单提交值为null
    shiro
    json简单介绍
    Sql Server 安装
    MySQL面试常问的查询操作
    关于分页
    Vuex
    Vue基础安装(精华)
  • 原文地址:https://www.cnblogs.com/ikai/p/14917569.html
Copyright © 2011-2022 走看看