远程图片下载到本地
function http_get_imgData($url) {
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_URL, $url );
ob_start ();
curl_exec ( $ch );
$return_content = ob_get_contents ();
ob_end_clean ();
$return_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
return $return_content;
}
// 获取到的内容 写入保存到本地
if(!file_exists($path.'/avatar')){
mkdir(iconv("UTF-8", "GBK", $path.'/avatar'),0777,true);
}
//定义文件名
$avatarImg = $path.'/avatar/'.$filename;
$filename = iconv("UTF-8", "GBK",$avatarImg);
$fp = @fopen($filename,"w+"); //将文件绑定到流 (以读写的模式写入)
fwrite($fp,$content); //写入文件
fclose($fp);
让每一滴智慧绘制成一条不归路!