php使用curl抓取微信上的图片

这个方法是经过我测试过的,确实可行,代码如下

<?php


$url = 'http://mmbiz.qpic.cn/mmbiz/vpR4I9Ay4AVpgpRM76I4C19gmAycRtcmvxddq77LhKKrkicczgBUfiaGiaC034EnzM5G9FEekaAosbxiaeLxwuK3ug/0?wx_fmt=jpeg';//微信图片地址


$ch = curl_init();

$httpheader = array(

'Host' => 'mmbiz.qpic.cn',

'Connection' => 'keep-alive',

'Pragma' => 'no-cache',

'Cache-Control' => 'no-cache',

'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8',

'User-Agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',

'Accept-Encoding' => 'gzip, deflate, sdch',

'Accept-Language' => 'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4'

);

$options = array(

CURLOPT_HTTPHEADER => $httpheader,

CURLOPT_URL => $url,

CURLOPT_TIMEOUT => 5,

CURLOPT_FOLLOWLOCATION => 1,

CURLOPT_RETURNTRANSFER => true

);

curl_setopt_array( $ch , $options );

$result = curl_exec( $ch );

curl_close($ch);

file_put_contents( './test.jpg', $result );

?>

可直接复制代码放到php中运行,在当前目录下显示下载到的图片test.jpg


你可能感兴趣的:(PHP,cur,微信图片)