php通过curl下载远程图片实例

Java代码  收藏代码
  1. <?php  
  2.     $url = 'http://mf1905.com/upload/video_img/df3074c98ec5124ad47c52ff59f74e04_middle.jpeg';  
  3.   
  4.     function http_get_data($url) {  
  5.           
  6.         $ch = curl_init ();  
  7.         curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );  
  8.         curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );  
  9.         curl_setopt ( $ch, CURLOPT_URL, $url );  
  10.         ob_start ();  
  11.         curl_exec ( $ch );  
  12.         $return_content = ob_get_contents ();  
  13.         ob_end_clean ();  
  14.           
  15.         $return_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );  
  16.         return $return_content;  
  17.     }  
  18.       
  19.     $return_content = http_get_data($url);  
  20.     $filename = 'test.jpg';  
  21.     $fp= @fopen($filename,"a"); //将文件绑定到流    
  22.     fwrite($fp,$return_content); //写入文件
posted @ 2018-01-21 14:56  追忆丶年华  阅读(263)  评论(0编辑  收藏  举报