我需要保存来自远程站点的图像。我的主机不允许file_get_contents,所以我想用curl。我正在使用代码获取corrput图像。请帮忙!以PHP格式保存来自远程服务器的图像
$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);
你看着这个被破坏的数据?这是一个局部图像? 0长度的文件?你有没有检查'$ rawdata'是否真的是一个布尔错误来表示curl以某种方式失败? – 2013-03-13 21:44:57
从未与Facebook合作过,是否有可能阻止你如何? – 2013-03-13 21:51:33
@MarcB $ rawdata为空 – user1871640 2013-03-13 21:53:00