-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadDropbox.php
34 lines (31 loc) · 1.05 KB
/
uploadDropbox.php
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
<?php
error_reporting(0);
$result = array('status' => 'error');
$fileName = date('dmY') . '-backup';
if (file_exists($fileName.'.zip')) {
$path = $fileName.'.zip';
$fp = fopen($path, 'rb');
$size = filesize($path);
$AccessToken = '___TOKEN___';
$cheaders = array('Authorization: Bearer '.$AccessToken,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/'.$_SERVER['HTTP_HOST'].'/'.$path.'", "mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response = json_decode($response,true);
//print_r($response);
curl_close($ch);
fclose($fp);
if (isset($response['id'])) {
unlink($fileName.'.zip');
$result = array('status' => 'success');
}
}
echo json_encode($result);
?>