-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost.php
More file actions
75 lines (69 loc) · 2.07 KB
/
post.php
File metadata and controls
75 lines (69 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
error_reporting(0);
include("./vendor/autoload.php");//Include Facebook Graph API
#Infromation BEGIN
$appId="{AppID}";
$appSecret="{AppSecret}";
$pageToken="{AccessToken}";
#Infromation END
#Create Graph API Begin
$fb = new Facebook\Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.9',
]);
#Create Graph API End
#Upload Image Begin
if ($_FILES["img"]["name"]==""){
//No Image Upload
$data = [
'message' => $_POST["content"],
];//Just Text Message
}else{
if ($_FILES["img"]["type"]=="image/png" || $_FILES["img"]["type"]=="image/jpeg"){
$target_path = "uploads/";//Target directory to upload
$target_path .= date("YmdHis").".jpg";//Name of the target image
if(move_uploaded_file($_FILES['img']['tmp_name'],iconv("UTF-8", "big5//TRANSLIT//IGNORE", $target_path ))) {
//upload success
$data = [
'message' => $_POST["content"],
'source' => $fb->fileToUpload($target_path),
];//Image with Text Message
} else{
//can't upload
header("Location ./index.php?err=ul");
exit;
}
}else{
//File isn't a image
header("Location: ./index.php?err=ftp");
exit;
}
}
#Upload Image End
#Call Graph to POST Begin
if ($_FILES["img"]["name"]==""){
try {
$response = $fb->post('/me/feed', $data, $pageToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
header("Location: ./index.php?err=gerr&detail=".urlencode($e->getMessage()));
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
header("Location: ./index.php?err=serr&detail=".urlencode($e->getMessage()));
exit;
}
}else{
try {
$response = $fb->post('/me/photos', $data, $pageToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
header("Location: ./index.php?err=gerr&detail=".urlencode($e->getMessage()));
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
header("Location: ./index.php?err=serr&detail=".urlencode($e->getMessage()));
exit;
}
}
$graphNode = $response->getGraphNode();
#Call Graph to POST End
#Finish!
header("Location: ./index.php?success=yes&detail=".urlencode($graphNode['id']));