Php Curl无法从url检索图像

Php Curl无法从url检索图像,php,curl,Php,Curl,我对PHP curl库有一个问题 在这个URL:http://i.ebayimg.com/00/s/NTAwWDUwMA==/z/7KcAAOxyRhBS3lhE/$\u 1.JPG?set\u id=880005007有一个图像。对于“卷曲”,图像不存在 我很困惑。按照我的方法: public static function downloadImage($url, $pathToSave = "") { $imageUrl = (string)$url; $ch =

我对PHP curl库有一个问题

在这个URL:
http://i.ebayimg.com/00/s/NTAwWDUwMA==/z/7KcAAOxyRhBS3lhE/$\u 1.JPG?set\u id=880005007
有一个图像。对于“卷曲”,图像不存在

我很困惑。按照我的方法:

public static function downloadImage($url, $pathToSave = "")
{
    $imageUrl = (string)$url;
    $ch       = curl_init($imageUrl);

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

    $raw = curl_exec($ch);
    curl_close($ch);

    if(file_exists($pathToSave))
    {
        unlink($pathToSave);
    }

    $fp = fopen($pathToSave, 'x');
    fwrite($fp, $raw);
    fclose($fp);

    return $pathToSave;
}
这对我很有用:

<?php
    $c = curl_init();
    curl_setopt($c,CURLOPT_URL,"http://i.ebayimg.com/00/s/NTAwWDUwMA==/z/7KcAAOxyRhBS3lhE/$_1.JPG?set_id=8800005007");
    curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
    $img = curl_exec($c);
    file_put_contents('image.jpg',$img);
?>

。。。因为许多站点拒绝提供由
CURL
自身请求的文件。

如果您尝试使用ssh中的基本CURL,其路径将不会下载,则可能重复,除非您指定-o标志。我建议您查看上述选项集,并尝试其中一些。@LiamSorsby谢谢您的回复。我看到了你的帖子,它很有效!
curl_setopt($c,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36 OPR/27.0.1689.54');