- 下边是抓取一个有防盗链图片的实例:
//请求地址
$url = "http://i.meizitu.net/2017/11/18b35.jpg";
//headers请求头
$context_options = array(
'http' =>
array(
'method' => "GET",
'header' => "User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\r\nReferer:http://www.mzitu.com/\r\n",
));
$context = stream_context_create($context_options);
//获取资源
$img = file_get_contents($url,FALSE,$context);
//保存
file_put_contents("./savePath/imageName.jpg",$img);
网友评论