Curl-How to Use PHP to download images Uploaded By WeChat users

Source: Internet
Author: User
Mmbiz. qpic. cnmmbizK6icFiaUPUZPxwORf6Eg7p9bgqVLWFyvEupNTTxhCgN... as shown in the figure above, it turns to the attempt to Add USER-AGENT and other information.

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

The image above is obtained with CURL and becomes

Try to Add USER-AGENT and other information.

Reply content:

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

The image above is obtained with CURL and becomes

Try to Add USER-AGENT and other information.

Maybe the resource server uses the leeching technology, similar to javafilterFilters
Determine whether to steal links based on information such as the requested browser type.
If yes, the system returns a normal result, and other requests directly return the leeching diagram.

Get the answer in the comment

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

$ Url = 'HTTP: // response ...';

$ Ch = curl_init ();
$ Httpheader = array (
'Host' => 'mmbiz .qpic.cn ',
'Connection' => 'keep-alive ',
'Pragm' => '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/80 ',
'Accept-encoding' => 'gzip, deflate, sdch ',
'Accept-color' => 'zh-CN, zh; q = 0.8, en; q = 0.6, zh-TW; q = 100'
);
$ 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 refer referenced in the webpage is equivalent to an external domain website, but this link can be opened if refer is empty, you can copy the image address to a new tab.

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.