PHP 获取远程图片显示(远程403)

<?php
$url = $_GET["url"];

if ( ! empty($url) && substr($url, 0, 4) == 'http') {
    $dirUrl = parse_url($url);
    $host   = ! empty($dirUrl['host']) ? $dirUrl['host'] : '';

    $ch         = curl_init();
    $httpheader = array(
        'Host'            => $host,
        'Connection'      => 'keep-alive',
        'Pragma'          => 'no-cache',
        'Cache-Control'   => 'no-cache',
        'Accept'          => 'textml,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8',
        'User-Agent'      => 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
        'Accept-Encoding' => 'gzip, deflate, sdch',
        'Accept-Language' => 'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4'
    );
    $options    = array(
        CURLOPT_HTTPHEADER     => $httpheader,
        CURLOPT_URL            => $url,
        CURLOPT_TIMEOUT        => 5,
        CURLOPT_FOLLOWLOCATION => 1,
        CURLOPT_RETURNTRANSFER => true
    );
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    header('Content-type: image/jpg');
    echo $result;
    exit;
} else {
    die("url为空哦");
}

?>
PHP 获取远程图片显示(远程403)
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    blank

    暂无评论内容