从谷歌通过curl下载后,图像为0大小的空白


image blank with 0 size after download via curl from google

嗨,我想下载这样的gmail配置文件图像:

$src = 'https://lh3.googleusercontent.com/-MsxFngq63hA/AAAAAAAAAAI/AAAAAAAAAFc/kKIrjln2a_s/photo.jpg?sz=200';

这种卷曲:

    $ch = curl_init ($src);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
    $fp=fopen("./imageProcess.jpg","w+");
    fwrite($fp,  $rawdata);
    fclose($fp);

但是结果图像是0大小的空白。

怎么了?

不完全是你的代码,但这一个更短,而且不复杂

<?php
    $content = file_get_contents($url);
    file_put_contents("a.jpg", $current);
?>

希望这有帮助,除非您还想编辑原始标题