我需要从远程站点保存图像。我的主机不允许 file_get_contents,所以我正在尝试使用 curl。我正在使用代码获取损坏的图像。请帮忙!
   $destination = realpath("../../app/webroot/img/uploads") . "/" . $facebook_id . "." . "gif";
    // Delete previous pic
    if (file_exists($destination)) {
        unlink($destination);
    }
    // Save new pic
    $remoteUrl = "https://graph.facebook.com/" . $facebook_id . "/picture";
    $ch = curl_init($remoteUrl);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $rawdata = curl_exec($ch);
    curl_close($ch);
    $fp = fopen($destination, 'w');
    fwrite($fp, $rawdata);
    fclose($fp);