2

用于上传图片的 HTML 表单

<form enctype="multipart/form-data" action="upload.php" method="POST">
   Please choose a photo:
   <input name="photo" type="file"><br/><br/>
   Say something about this photo:
   <input name="message" type="text" value=""><br/><br/>
   <input type="submit" value="Upload"/><br/>
</form>

HTML 表单将重定向到 upload.php

upload.php 文件的代码..

<?php 
//upload.php
if(isset($_FILES['photo']) && isset($_POST['message'])){

    $uploadfile ='./uploads/'.basename($_FILES['photo']['name']);


    $iStats=getimagesize($_FILES['photo']['tmp_name']);


    if (isset($iStats['mime']) && $iStats[0]>0) {

    move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
    require_once('sdk/src/facebook.php');
    require_once('utils.php');
    require_once('AppInfo.php');
    try{

        //this one is used to find the APPID and secret of the app

        $facebook = new Facebook(array(
                    'appId'  => AppInfo::appID(),
                    'secret' => AppInfo::appSecret(),
                    'sharedSession' => true,
                    'trustForwarded' => true,
                    ));

        $album_details = array(
                'message'=> 'Album desc',
                'name'=> 'Album name'
                );



        $uid = $facebook->getUser();  //used to get the user id

        $me = $facebook->api('/me');

    $token = $facebook->getAccessToken(); //here I get the token from the $session array

        $create_album = $facebook->api('/me/albums', 'post', $album_details);

            $album_id = $create_album['id'];

        $facebook->setFileUploadSupport(true);
        $args['image'] = '@' . realpath($uploadfile);

     $data = $facebook->api('/'. $album_id . '/photos?access_token='. $token, 'post', $args['image']);

       //     $data = $facebook->api('/'.$album_id.'/photos', 'post', $args['image']);

    } catch(FacebookApiException $e){
        echo "Error:" .$e;
    }
    unlink($uploadfile);
    echo "Success!\n";
    } else {
    echo "Wrong file type!\n";
    }
}

?>

我收到以下错误

错误:OAuthException:(#324)需要上传文件

4

0 回答 0