-
Notifications
You must be signed in to change notification settings - Fork 12
/
gdrive.php
executable file
·77 lines (55 loc) · 1.97 KB
/
gdrive.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
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
76
<?php
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
session_start();
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$url_array = explode('?', $protocol.$_SERVER ['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$url = $url_array[0];
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
$client->setClientId('560284086204-84dco8h09i1bidq6g6v0j2oj2p14dnjp.apps.googleusercontent.com');
$client->setClientSecret('U9cvNk2ARBeJ5AdqKOrDgqaN');
$client->setRedirectUri($url);
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
if (isset($_GET['code'])) {
$_SESSION['accessToken'] = $client->authenticate($_GET['code']);
header('location:'.$url);exit;
} elseif (!isset($_SESSION['accessToken'])) {
$client->authenticate();
}
if (!empty($_GET)) {
$file = './split/'.$_GET['file'];
if(isset($_GET['delete'])){
unlink($file);
echo 'deleted <br /> exit.';
header('Location: '.str_replace('gdrive', 'upload', $url));
}
$data = file_get_contents($file);
$client->setAccessToken($_SESSION['accessToken']);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
$mime_type = finfo_file($finfo, $file);
$file->setTitle($_GET['file']);
$file->setDescription('uploaded');
$file->setMimeType($mime_type);
$service->files->insert(
$file,
array(
'data' => $data,
'mimeType' => $mime_type
)
);
finfo_close($finfo);
echo 'uploaded';
header('Location: '.str_replace('gdrive', 'upload', $url));
}