nodejs做盗链图片中转
emer 发布于 2018-8-7 14:23 2320 次阅读
var express = require('express');
var router = express.Router();
var request = require('request');
var router = express.Router();
/ GET home page. /
router.get('/', function(req, res, next) {
var url=req.query.url;
var options = {
method: "GET",
url:url,
headers:{
"Referer": request.host
}
};
request(options).pipe(res);
});
module.exports = router;
<?php function Crack_img($url,$refer){ $ch = curl_init($url); //设置图片url curl_setopt ($ch, CURLOPT_REFERER, $refer); //伪造请求来源 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); //$ext = strtolower(substr(strrchr($img,'.'),1,10)); //输出图片格式 /*$types = array( 'gif'=>'image/gif', 'jpeg'=>'image/jpeg', 'jpg'=>'image/jpeg', 'jpe'=>'image/jpeg', 'png'=>'image/png', );*/ //$type = $types[$ext] ? $types[$ext] : 'image/jpeg'; header("Content-type:image/jpeg"); //输出二进制流图片 return $data;} $url = $_GET["url"]; $refer = $_GET['refer']; echo Crack_img($url,$refer);
https://image.baidu.com/search/down?tn=download&url=