繁体   English   中英

PHP使用Fopen下载Facebook图像

[英]Php download facebook images with fopen

我正在尝试在VPS上运行此代码

    <?php 
    function curl_get_contents($url, array $opts = array()) {
    $defaults = array(
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_USERAGENT => 'Mozilla Firefox 20.0',
        CURLOPT_VERBOSE => true
    );
    $opts = $opts + $defaults;
    $ch = curl_init($url);
    curl_setopt_array($ch, $opts);

    return curl_exec($ch);
}

header('Content-type: image/jpeg');
echo curl_get_contents('http://sphotos-b.ak.fbcdn.net/hphotos-ak-prn1/58678_10151328142003680_1939974573_n.jpg');

?> 

当我运行它时,有一个无限循环,我不明白为什么。 该功能适用​​于每个图片网址,但不适用于Facebook。 有什么建议吗?

以下为我工作:

<?php
function curl_get_contents($url, array $opts = array()) {
    $defaults = array(
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_USERAGENT => 'Mozilla Firefox 20.0'
    );
    $opts = $opts + $defaults;
    $ch = curl_init($url);
    curl_setopt_array($ch, $opts);

    return curl_exec($ch);
}

header('Content-type: image/jpeg');
echo curl_get_contents('link to facebook image');
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM