Curl-How to download images uploaded by WeChat users in PHP

Source: Internet
Author: User

Http://mmbiz.qpic.cn/mmbiz/K6icFiaUPUZPxwORf6Eg7p9bgqVLWFyvEupNTTxhCgN ...

Like the picture above, using curl to get it becomes

Try to add user-agent and other information or not.

Reply content:

Http://mmbiz.qpic.cn/mmbiz/K6icFiaUPUZPxwORf6Eg7p9bgqVLWFyvEupNTTxhCgN ...

Like the picture above, using curl to get it becomes

Try to add user-agent and other information or not.

Maybe the resource server uses hotlinking technology, something like a Java filter filter.
Determines whether hotlinking is based on information such as the requested browser type.
Is the normal return, other requests are returned directly to the hotlinking diagram.

The answer in the comments

' User-agent ' = ' mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/41.0.2272.89 safari/537.36 ',

$url = ' Http://mmbiz.qpic.cn/mmbiz/K6icFiaUPUZPxwORf6Eg7p9bgqVLWFyvEupNTTxhCgN ... ';

$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 ('./i.jpg ', $result);

This should be related to refer, the page refers to the refer relative to the other site, but the refer is empty case is can open the link, the landlord can copy the picture address to a new tab open try

Adsfasdfasd

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.