1

我正在使用一个名为 yii-facebook-opengraph 的扩展程序,用于从 facebook 登录。我正在后端获取详细信息并将它们保存在数据库中。在这里,我也在获取用户图像,当我将用户图像保存在文件夹中时,它会保存图像,但大小为 0kb。

我正在使用的代码如下:

 $image = "http://graph.facebook.com/".$IsUser->social_key."/picture?type=normal";

    $img_file = file_get_contents($image);
    $file_loc = Yii::app()->basePath.'/../images/userimag/'.$IsUser->id.'.jpg';
    $file_handler=fopen($file_loc,'w');
    if(fwrite($file_handler,$img_file)==false){
          echo 'error';
    }
    fclose($file_handler);
    $model->profile_image = $IsUser->id.'.jpg';
    $model->save(false);

当我打印图像 url $image 我得到图像,但是当我打印 $img_file 它显示为空

4

1 回答 1

1

使用它来存储图像文件,如果您已allow_url_fopen设置为true

$url = "http://graph.facebook.com/".$IsUser->social_key."/picture?type=normal";
$img = Yii::app()->basePath.'/../images/userimag/'.$IsUser->id.'.jpg';
file_put_contents($img, file_get_contents($url));
于 2013-04-08T07:49:06.540 回答