-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropbox_functions.php
42 lines (32 loc) · 1.48 KB
/
dropbox_functions.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
35
36
37
38
39
40
41
42
<?php
/**
* Functions for sending results to Dropbox
*
* @author Mikhail Glagolev <mikhail.glagolev@gmail.com>
* @copyright 2017 - 2019 for dear Anita
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0
* @link https://github.com/mglagolev/quiz
*/
function upload_string_contents_to_dropbox($remote_filename, $file_contents, $token)
{
$test_results_dir = __DIR__.'/tmp_english_test_results';
$test_results_prefix = 'test_results_';
ignore_user_abort(true);
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Auth.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/FileProperties.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/FileRequests.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Files.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Misc.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Paper.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Sharing.php';
require __DIR__.'/Dropbox-v2-PHP-SDK-master/sdk/Dropbox/Users.php';
$tmp_filename = tempnam($test_results_dir, $test_results_prefix);
file_put_contents($tmp_filename, $file_contents);
// Initialize Dropbox client
$dropbox = new Dropbox\Dropbox($token);
// Upload a file, overwriting if the file already exists in Dropbox
$dropbox->files->upload($remote_filename, $tmp_filename, "overwrite");
unlink($tmp_filename);
}
?>