Facebook APIを使用してアプリユーザーのプロフィール写真を取得し、サーバーに保存しようとしています。画像は問題なく取得できていますが、新しい画像ファイルを作成して正しいフォルダーに保存するのに問題があるようです。fopen 関数と file_put_contents 関数を使用してみましたが、ファイルを事前に作成する必要があるようです。fb ユーザーの画像をサーバーに保存するにはどうすればよいですか? 私のコードは次のとおりです。
$facebook = new Facebook(array(
'appId' => '12345',
'secret' => '12345',
'cookie' => true
));
$access_token = $facebook->getAccessToken();
if($access_token != "")
{
$user = $facebook->getUser();
if($user != 0)
{
$user_profile = $facebook->api('/me');
$fb_id = $user_profile['id'];
$fb_first_name = $user_profile['first_name'];
$fb_last_name = $user_profile['last_name'];
$fb_email = $user_profile['email'];
$img = file_get_contents('https://graph.facebook.com/'.$fb_id.'/picture?type=large');
$file = '/img/profile_pics/large/';
rename($img, "".$file."".$img."");
}
助言がありますか?
ありがとう、
ランス