解决苹果CMS v10因豆瓣图片防盗链导致无法正常显示图片问题

解决苹果CMS v10因豆瓣图片防盗链导致无法正常显示图片问题

William
2021-09-25 / 0 评论 / 51 阅读 / 正在检测是否收录...

找到如图所示附件参数配置,填写好接口和标识即可。

防盗链关键词

并在CMS根目录创建一个反盗链接口文件命名为 img.php 即可解决豆瓣图片无法正常显示的问题。

<?php
error_reporting(E_ERROR | E_PARSE );
@ini_set('max_execution_time', '0');
@ini_set("memory_limit",'-1');
$url = $_GET["url"];
if (!empty($url) && substr($url,0,4)=='http') {
    $dir = pathinfo($url);
    $host = $dir['dirname'];
    $ext = $dir['extension'];
    $refer = $host.'/';
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_REFERER, $refer);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $data = @curl_exec($ch);
    curl_close($ch);
    $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: ".$type);
    echo $data;
}
0

评论 (0)

取消