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