Php-url Method Download Remote picture

Source: Internet
Author: User

The Php-url method can also download images that are restricted by use, such as pictures on a server

The function code is as follows:

1  Public functionDownloadpic () {//test feasible, online viewing, remote download pictures * /2         $return _content=$this->https_request ($listsInfo[0] [' Photo_url ']);//Pass the URL of the picture to the URL method to get the picture content3         $filename= ' E:\phpStudy\WWW\web1\wexin\public\static\uploads\list.jpg '; 4         $fp= @fopen($filename, "a");//bind a file to a stream?? 5         Var_dump(fwrite($fp,$return _content));//Write File6}

The Https_request method is as follows:

1  Public functionHttps_request ($url)//Compact version of the Curl interface call function2 {3      $curl=curl_init ();4curl_setopt ($curl, Curlopt_url,$url);5curl_setopt ($curl, Curlopt_ssl_verifypeer,FALSE);6curl_setopt ($curl, Curlopt_ssl_verifyhost,FALSE);7curl_setopt ($curl, curlopt_returntransfer,1);8      $data=curl_exec ($curl);9      if(Curl_errno ($curl)){return' ERROR '. Curl_errno ($curl);}TenCurl_close ($curl); One      return $data; A}

Curl method is more powerful, can not only call interface and crawl content, do web crawler.

Php-url Method Download Remote picture

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.