php file_get_content获取资源时添加heade

2017-11-19  本文已影响57人  腿长袖子短
//请求地址
$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);
上一篇下一篇

猜你喜欢

热点阅读