如何在不使用file_get_contents()的情况下将Facebook用户显示的图片保存到磁盘`


How save Facebook user display picture to the disk Without using file_get_contents()`?

你好,我正在尝试获取用户配置文件图片,然后根据我的Facebook应用程序要求合并到现有图像中。为此,我需要检查它的默剧时间等。但我在检索和保存图片时遇到了困难。

        $facebook = new Facebook($config);
        $user = $facebook -> getUser();
        if ($user) {
            $user_profile = $facebook -> api('/me');
        }
        //User Info. Variables:
        try {
            $userPpicture = $user_profile[picture];
            }

现在我们已经检索到了这个,我想把这个图像保存在磁盘上,这样我就可以检查它的mime时间等,以便进一步处理,我该如何实现?

p.s.由于我的托管服务器限制,我无法使用函数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

是否允许使用CURL?

如果是,请按照http://phpsense.com/2007/php-curl-functions/