Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE); $app_id="xxxxxxxxxxxxx" ; $app_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxx" ; $my_url="`http://localhost/facebook/examples/example.php`" ; $perms_str="publish_stream" ; $code=$ _REQUEST[ "code"]; if(empty($code)) { $auth_url="http://www.facebook.com/dialog/oauth?client_id="
  3. . $app_id . "&redirect_uri=" . urlencode($my_url). "&scope=" . $perms_str; echo( "<script>top.location.href='" . $auth_url . "'</script>"); } $token_url="https://graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url).
  4. "&client_secret=" . $app_secret. "&code=" . $code; $response=f ile_get_contents($token_url); $p=n ull; parse_str($response, $p); $access_token=$ p[ 'access_token']; $graph_url="https://graph.facebook.com/me/photos?" . "access_token=" .$access_token; if (!empty($_FILES))
  5. { $params=a rray(); if( isset($_POST[ 'message']) ) { $params[ 'message']=t rim($_POST[ 'message']); } $uploaddir='./uploads/' ; // Upload folder $uploadfile=$ uploaddir . basename($_FILES[ 'source'][ 'name']); if (move_uploaded_file($_FILES[ 'source'][
  6. 'tmp_name'], $uploadfile)) { $params[ 'source']="@" . realpath($uploadfile); } // Start the Graph API call $ch=c url_init(); curl_setopt($ch, CURLOPT_URL,$graph_url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,
  7. CURLOPT_POSTFIELDS, $params); $result=c url_exec($ch); $decoded=j son_decode($result, true); curl_close($ch); if(is_array($decoded) && isset($decoded[ 'id'])) { $msg="Image uploaded successfully: {$decoded['id']}" ; } }
  8. ?>
  9. <!doctype html>
  10. <html>
  11.  
  12. <head>
  13. <title>Upload</title>
  14. </head>
  15.  
  16. <body>
  17. <?php if( isset($msg) ) { ?>
  18. <p id="msg">
  19. <?php echo $msg; ?>
  20. </p>
  21. <?php } ?>
  22. <form enctype="multipart/form-data" action="" method="post">
  23. <p>
  24. <label for="name">Caption</label>
  25. <input type="text" name="message" value="" />
  26. </p>
  27. <p>
  28. <label for="source">Image</label>
  29. <input type="file" name="source" />
  30. </p>
  31. <p>
  32. <input type="submit" value="Upload" />
  33. </p>
  34. </form>
  35. </body>
  36.  
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement