<?php
namespace app\index\controller;
class Temp
{
//下载学校logo
public function getImg(){
$img_path = 'https://static-data.eol.cn/upload/logo/102.jpg';
$this->downloadImage($img_path);
}
public function downloadImage($url, $path='./images/')
{
//模拟请求源IP地址【暂用百度地址段】
$cip = '123.125.68.'.mt_rand(0,254);
$xip = '125.90.88.'.mt_rand(0,254);
$header = array(
'CLIENT-IP:'.$cip,
'X-FORWARDED-FOR:'.$xip,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/");
$file = curl_exec($ch);
curl_close($ch);
$this->saveAsImage($url, $file, $path);
}
public function saveAsImage($url, $file, $path)
{
$filename = pathinfo($url, PATHINFO_BASENAME);
$resource = fopen($path . $filename, 'w+');
fwrite($resource, $file);
fclose($resource);
}
}
暂无评论