2种存图片

if ($loadface) {
if (!empty($info['headimgurl'])) {
$filepatch = 'weixin/' . substr(md5($openid), 0, 3) . '/';
$dir = BASE_PATH . '/attachs/' . $filepatch;
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$faceimg = $dir . $openid . '.png';
//if (!file_exists($faceimg)) {//如果不存在 2017.4.24 panhan file_get_contents阿里禁掉了 改为curl下载图片
$ch = curl_init();
$fp = fopen($faceimg, 'wb');
curl_setopt($ch, CURLOPT_URL, $info['headimgurl']);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_exec($ch);
curl_close($ch);
fclose($fp);
//$face = file_get_contents($info['headimgurl']);
//file_put_contents($faceimg, $face);
// }
$info['headimgurl'] = '/' . $filepatch . $openid . '.png';
}
}

posted @ 2017-04-24 14:09  哼哼哈兮啊  阅读(159)  评论(0编辑  收藏  举报