【发布时间】:2012-08-18 16:21:21
【问题描述】:
我想将用户的个人资料图片放在另一张图片上,我尝试了以下代码来检索用户个人资料图片
$url='https://graph.facebook.com/'.$uid.'/picture?type=large';
$userpic = imagecreatefromjpeg($url);
imagejpeg($userpic, "xyz.jpg", 100);
但是我收到了这个错误:
imagecreatefromjpeg() [function.imagecreatefromjpeg]: Cannot read image data in /home/a3111484/public_html/fb/index.php
我也尝试了file_get_contents(),但在这种情况下,只会创建一个空的 jpg 文件。
请帮我找出问题所在。
我也尝试了 cURL 方式,但得到了这个错误:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a3111484/public_html/fb/index.php on line 31
【问题讨论】:
-
该代码是否已简化?第 2 行定义了
$userpic,但第 3 行使用了$mainphoto。此外,由于这两行之间没有进行任何修改,为什么需要使用imagecreatefromjpeg和imagejpeg而不仅仅是下载原始数据?或者,就此而言,热链接到 facebook 托管的图像? -
@IMSoP 对不起,我现在更新了代码。实际上我需要修改图像,因为这样它不起作用我尝试使用 file_get_contents() 下载图像但它什么也没检索。
-
您可以从以下链接获得帮助。 [点击这里][1] [1]:stackoverflow.com/questions/5429964/…
-
啊,好的。
file_get_contents()是否返回任何数据(尝试echo strlen(file_get_contents($url));)?请注意,这种下载数据的方法依赖于 PHP 设置allow_url_fopen(uk3.php.net/manual/en/…),这可能在您的服务器上被禁用。如果是这种情况,您需要尝试另一种方法,例如 CURL (php.net/curl) -
@IMSoP Nothing, echo strlen(file_get_contents($url));返回 0
标签: php facebook user-profile