zoukankan      html  css  js  c++  java
  • 判断文件格式并输出文件流

    首先需要一个curl的方法 然后获取头信息 输出文件流

    <?php
    function my_request($url, $data = null,$return_header=false)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_TIMEOUT,10);//设置超时时间
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if($return_header)
        {
            curl_setopt($curl, CURLOPT_HEADER, 1);//返回header信息
        }    
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    $url="http://images2017.cnblogs.com/blog/704203/201708/704203-20170823105514714-1139981147.gif";
    $stream=my_request($url,null,false);
    $header=my_request($url,null,true);
    $start=strpos($header,"Content-Type");
    $to_header=substr($header,$start);
    $end=strpos($to_header,"
    ");
    $real=trim(substr($to_header,0,$end));
    if($real)
    {
        header($real);
        echo($stream);
    }else
    {
        die("can not found file type");
    }
    exit();
    ?>
  • 相关阅读:
    冷水花
    石竹
    红花酢浆草
    紫鸭跖草
    吊竹梅
    花叶络石
    牡丹
    CF1190D Tokitsukaze and Strange Rectangle
    CF1178D Prime Graph
    CF958E2 Guard Duty (medium)
  • 原文地址:https://www.cnblogs.com/lizhaoyao/p/7447642.html
Copyright © 2011-2022 走看看