-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
57 lines (42 loc) · 1.65 KB
/
upload.php
File metadata and controls
57 lines (42 loc) · 1.65 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
<?php
//Developed by Pinal Zala
include_once 'functions.php';
$token = dropbox_tokenstore::acquire_token(); // Call this function to grab a current access_token, or false if none is available.
if (!$token)
{
} else
{
$folder_id =$_GET['folder_id'];
$target_dir = ""; // for example you are taking image from the upload directory
$target_file = $target_dir . basename('1.jpg'); // for example if file name is 1.png write 1.png in file nanme
$api_url = 'https://content.dropboxapi.com/2/files/upload'; //dropbox api url
$headers = array('Authorization: Bearer '. $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"path"=> $folder_id."/". basename('1.jpg'),
"mode" => "add",
"autorename" => true,
"mute" => false
)
)
);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
$fp = fopen($target_file, 'rb');
$filesize = filesize($target_file);
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp, $filesize));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode == "200") {
return json_decode($response, true);
} else {
return array('error' => 'HTTP status code not expected - got ', 'description' => $httpcode);
}
curl_close($ch);
}
?>