Jump to content

Recommended Posts

No one is going to give you the code - coding is what most of us get paid to do. Start with the APIs and documentation that QuickOldCar link to above, Google, and try some things. When you get stuck, come on here and tell us what you've tried, show us the code you've written, and we'll help where we can.

Link to comment
https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518417
Share on other sites

Okay, so i dont know to work with API but im trying

So this is my simple code

<form action="" method="post">
<input type="file" name="fileToUpload">
<button>Upload</button>
</form>


<?php

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
    $fb = new Facebook\Facebook([
 'app_id' => 'myappid',
 'app_secret' => 'myappsecret',
 'default_graph_version' => 'v2.4',
 ]);

$data = [
 'message' => 'My awesome photo upload example.',
 'source' => $fb->fileToUpload($target_dir),
];

try {
 // Returns a `Facebook\FacebookResponse` object
 $response = $fb->post('/me/photos', $data, 'myaccesstoken');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
 echo 'Graph returned an error: ' . $e->getMessage();
 exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 echo 'Facebook SDK returned an error: ' . $e->getMessage();
 exit;
}

$graphNode = $response->getGraphNode();

echo 'Photo ID: ' . $graphNode['id'];
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}

?>

I got this error message
 

Notice: Undefined index: fileToUpload in C:\wamp\www\fb.php on line 10

What is wrong in code for upload?

Btw. are code for facebook API good?

Edited by Ex1t
Link to comment
https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518421
Share on other sites

1 - you are using $_POST in your code but since your form doesn't have a method set the $_POST array won't have your inputs

2 - You also reference an input name of 'submit' but I don't see that in your form

3 - I don't see where you included the class so that could certainly explain your new error now as well as the above two items.

4 - add php error checking to help you debug what will probably be many future errors. See my signature.

Link to comment
https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518425
Share on other sites

Did you fix the problems I pointed out? When you do how about isolating the new problem area(s) and posting those snippets of code for us to address? I, for one, will not be going to your external post no matter where it is hosted, so I won't be any help until you do the necessary work to get close to your problem and ask a pertinent question.

Link to comment
https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518478
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.