首页 > 代码库 > curl 抓取图片
curl 抓取图片
/** * curl 抓取图片 * @param $url * @return mixed */ public static function downLoadImage($url) { $header = array(‘Expect:‘); $ch = curl_init(); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘GET‘); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $img = curl_exec($ch); curl_close ($ch); //$return_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE ); return $img; }
foreach ($productData as $val) { $serviceParams[‘model_id‘] = $val[‘id‘]; // 调用逻辑层 $qrcodeService->getQrcode($serviceParams); // 接收逻辑层处理结果 if (!is_null($qrcodeService->getError())) { return $this->setError($qrcodeService->getError()); } $qrcode = CommonLib::downLoadImage($qrcodeService->_data); //重试一次 if (!$qrcode) { $qrcode = CommonLib::downLoadImage($qrcodeService->_data); } //重名重写 if (isset($name[$val[‘name‘]])) { $name[$val[‘name‘]]++; $val[‘name‘] = $val[‘name‘] . ‘(‘ . $name[$val[‘name‘]] . ‘)‘; } $name[$val[‘name‘]] = 0; file_put_contents(iconv(‘utf-8‘, ‘gbk‘, $dir . DIRECTORY_SEPARATOR . $val[‘name‘] . ‘.png‘), $qrcode); }
curl 抓取图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。