nodejs做盗链图片中转

Others 2018-08-07 06:23:24 2018-08-07 06:23:24 2335 次浏览

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'=&gt;'image/gif',  
            'jpeg'=&gt;'image/jpeg',  
            'jpg'=&gt;'image/jpeg',  
            'jpe'=&gt;'image/jpeg',  
            'png'=&gt;'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);</pre>
https://image.baidu.com/search/down?tn=download&url=