【问题标题】:How save Facebook user display picture to the disk Without using file_get_contents()`?如何在不使用 file_get_contents() 的情况下将 Facebook 用户显示图片保存到磁盘?
【发布时间】: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


【解决方案1】:

你可以使用 CURL 吗?

如果是这样,请关注http://phpsense.com/2007/php-curl-functions/

【讨论】:

  • 我用 cURL 更新了我的代码,我相信它不能正常工作,请看一下。
  • 请自行调试。 var_dump 返回值,查看是否确实有文件写入您的服务器,检查相关函数返回值,... 编辑:CURLOPT_FOLLOWLOCATION 可能丢失。
猜你喜欢
  • 2012-03-18
  • 2023-02-08
  • 2022-06-29
  • 1970-01-01
  • 1970-01-01
  • 2019-03-19
  • 1970-01-01
  • 2012-01-17
  • 1970-01-01
相关资源
最近更新 更多