码迷,mamicode.com
首页 > Web开发 > 详细

curl请求 和二进制图片处理

时间:2015-05-29 17:22:43      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 1      
 2 $ch = curl_init(); 
 3 curl_setopt($ch, CURLOPT_URL,$url.$token);  
 4         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0 ); // 跳过ssl证书检查
 5         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2 ); //检查证书是否有(common name)字段 及判断当前域名与证书是否匹配
 6         curl_setopt($ch, CURLOPT_HEADER, TRUE);    //表示需要response head 没有head时 全部都是内容
 7         curl_setopt($ch, CURLOPT_POST, 1 ); // post请求
 8         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
 9         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 不输出获取的内容
10 
11         $response = curl_exec($ch);
12      
13         if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == ‘200‘) {  
14 
15         //有head时候 需要将head 和内容拆分开 
16         list($header, $data) = explode("\r\n\r\n", $response, 2);
17      }
18  curl_close ( $ch );        
 1  $tempfile = @fopen($_SERVER[‘DOCUMENT_ROOT‘].‘/authok.png‘, "rb");
 2 $bin = fread($tempfile,2); //只读2字节
 3 $strInfo = @unpack("C2chars", $bin);
 4         $typeCode = intval($strInfo[‘chars1‘] . $strInfo[‘chars2‘]);
 5         $fileType = ‘‘;
 6         switch ($typeCode){ // 6677:bmp 255216:jpg 7173:gif 13780:png 7790:exe 8297:rar 8075:zip tar:109121 7z:55122 gz 31139
 7             case ‘255216‘:
 8                 $fileType = ‘jpg‘;
 9                 break;
10             case ‘7173‘:
11                 $fileType = ‘gif‘;
12                 break;
13             case ‘13780‘:
14                 $fileType = ‘png‘;
15                 break;
16             default:
17                 $fileType = ‘unknown‘;
18         }
19         echo $fileType;

 

curl请求 和二进制图片处理

标签:

原文地址:http://www.cnblogs.com/balyd/p/4538510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!