1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Pic Upload

Discussion in 'Facebook API' started by SSS Technology, Aug 7, 2011.

  1. #1
    can its possible we can upload lots of pics in a single attempt,i tried but unable to did it.is any software i have to use...
     
    SSS Technology, Aug 7, 2011 IP
  2. TsubasaOzora

    TsubasaOzora Well-Known Member

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    #2
    what u want to do ? upload a pics to facebook ?

    its possible..
     
    TsubasaOzora, Aug 9, 2011 IP
  3. TsubasaOzora

    TsubasaOzora Well-Known Member

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    #3
    What you need : Facebook APP ID and Secret ( You can get by make a new apps from http://facebook.com/developers)

    make a folder ( in my case i make 'z' folder with 777 permission)

    in your code, you need your user to allow publish_stream permission

    after user allow your apps. make a form to upload file, and insert Photo Caption



    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
        <p>
        <input type="file" id="image2" name="image2" size="35" />
        </p>
        <p>
        <label>caption
        <input name="cap" type="text" id="cap">
        </label>
        </p>
        <p>
        <input type="Submit" name="Submit" value="Submit" />
        </p>
        </form>
    HTML:
    and in server side.. this will do the tricks..

      <?
        function getExtension($str) {
        $i = strrpos($str,".");
        if (!$i) { return ""; }
        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);
        return $ext;
        }
    
        if (isset($_POST['Submit']))
        {
        $caption = $_POST['cap'];
        $filename = stripslashes($_FILES['image2']['name']);
        $extension = getExtension($filename);
        $extension = strtolower($extension);
    
        $image_name=time().'.'.$extension;
        $newname="z/".$image_name;
        $dua = $newname;
        $copied = copy($_FILES['image2']['tmp_name'], $newname);
    
        $args = array(
        'message' => $caption ,
        );
        $args[source] = '@' . realpath($dua);
    
        $ch = curl_init();
        $url = 'https://graph.facebook.com/me/photos?access_token='.$token;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);
    
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        $data = curl_exec($ch);
    
        $z = json_decode($data, true);
    
        $idalbum =  $z[id];
    
        echo $idalbum;
    
        }
        ?>
    PHP:
    Source code and Demo available to download at my site ( at my signature) : HERE
     
    TsubasaOzora, Aug 9, 2011 IP