There is a download link to the picture, php how to download pictures to local

Source: Internet
Author: User
The patch link address is as follows: http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadFile&fid= 917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga| |
Using PHP to automatically download to the local, I use file_get_contents and curl two methods are unsuccessful.

The method code I use is as follows:
1) file_get_contents:
$img = file_get_contents (' http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadFile&fid= 917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga| | ');
File_put_contents (' 1.jpg ', $img);

2) Curl
$ch = Curl_init ();
curl_setopt ($ch, curlopt_post, 0);
curl_setopt ($ch, Curlopt_url, ' http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadFile&fid= 917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga| | ');
curl_setopt ($ch, Curlopt_returntransfer, 1);
$file _content = curl_exec ($ch);
Curl_close ($ch);
$downloaded _file = fopen (' 1.jpg ', ' W ');
Fwrite ($downloaded _file, $file _content);
Fclose ($downloaded _file);

Hope advice, thank you here.


Reply to discussion (solution)

Curl is missing:
curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent ');

File_get_contents missing third parameter number:
$context = stream_context_create (Array (' http ' = = Array (' user_agent ' + $_server[' http_user_agent ')));

http://blog.csdn.net/shrimpma/article/details/9816035

  • 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.