【发布时间】:2012-03-25 21:33:26
【问题描述】:
您好,我正在尝试获取用户个人资料图片,然后根据我的 Facebook 应用要求合并到现有图片中。为此,我需要检查它的 mime 时间等。但我在检索和保存图片时遇到了困难。
$facebook = new Facebook($config);
$user = $facebook -> getUser();
if ($user) {
$user_profile = $facebook -> api('/me');
}
//User Info. Variables:
try {
$userPpicture = $user_profile[picture];
}
现在我已经检索到了,我想将此图像保存在磁盘上,以便检查其 mime 时间等以进行进一步处理,我该如何实现?
附言。由于我的托管服务器限制,我无法使用功能file_get_contents()。所以我需要一个除此之外的解决方案。
请帮助。 谢谢。
cURL 尝试:
//Create image instances
$url = "http://graph.facebook.com/{$userId}/picture?type=large";
$dpImage = 'temp/' . $userId . '_dpImage_' . rand().'.jpg';
echo $dpImage;
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data($url);
file_put_contents($dpImage, $returned_content);
echo "Type: " . exif_imagetype($dpImage);
在检查图像的 MIME 类型时出现此错误:
Notice: exif_imagetype(): Read error! in
【问题讨论】:
-
@Baba: no
fopen也被禁用。还有其他选择吗?
标签: php facebook facebook-graph-api curl facebook-php-sdk