Php Facebook从电脑上传照片
我正在尝试制作一个facebook应用程序,将照片从电脑上传到facebook上的特定相册。我有下面的代码,但我得到一个错误:创建formpost数据失败Php Facebook从电脑上传照片,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在尝试制作一个facebook应用程序,将照片从电脑上传到facebook上的特定相册。我有下面的代码,但我得到一个错误:创建formpost数据失败 require_once 'include.php'; $config = array( 'appId' => $app_id, 'secret' => $app_secret, ); $facebook = new Facebook($config); $user = $facebook->getU
require_once 'include.php';
$config = array(
'appId' => $app_id,
'secret' => $app_secret,
);
$facebook = new Facebook($config);
$user = $facebook->getUser();
if($user && isset($_POST['submit'])){
try {
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'POST', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo = realpath($_FILES['miss_photo']['tmp_name']);
$photo2 = $photo . '.jpg';
//echo $photo2; exit();
$photo_details['image'] = '@' . $photo2;
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'POST', $photo_details);
} catch (FacebookApiException $e) {
echo ($e->getMessage());
}
}
else
echo 'error';
知道我为什么会收到错误消息吗?您不能以这种方式使用文件,您需要提供文件的路径,如:
photo_details = array(
'message'=> 'some test'
);
$photo_details['image'] = '@' . realpath('/path/to/your/image_file.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
希望这有帮助否,错误是创建formpost数据失败,当然与文件名有关。但是什么?你把文件从临时文件夹移到真实的地方了吗?没有。这可能是问题所在?看看这里:我没有路径。这个文件存储在我的电脑里。我的意思是在上传它的用户的计算机中。