GoogledriveuploadpdfController.php
2.09 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers;
use App\pdfModel;
use URL;
use Storage;
use Response;
use File;
Use PDF;
use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Facade;
use League\Flysystem\Filesystem;
use Curl\Curl;
use Google_Client;
use Google_Service_Drive;
use Imagick;
class GoogledriveuploadpdfController extends Controller
{
public function google_drive_upload($folder, $filename)
{
$pdffile = new FileEntryController();
$pdfFile = $pdffile->getPDF($folder, $filename);
$client = new \Google_Client();
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
$client->setClientId('206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com');
$client->setClientSecret('qmUMAi09SU4wU4R3uOkvsiwK');
$client->setRedirectUri('http://pdf-customizer.synapsus.co/auth/google/callback');
// error_log(print_r($client,true));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else
$client->setAccessToken($_SESSION['access_token']);
$dr_service = new \Google_Service_Drive($client);
//error_log(print_r($dr_service ,true));
$file = new \Google_Service_Drive_DriveFile();
$mimetype = 'application/pdf';
$uploadType = 'media';
$filetitle = $filename;
//$filedescription = 'Taskew ' . $model['discussion_title'];
$datetime = date('d-m-y-h:s');
$file->setTitle($datetime . $filetitle);
$file->setDescription('');
$file->setMimeType($mimetype);
$data = $pdfFile;
$createdFile = $dr_service->files->insert($file, array(
'data' => $data,
'mimeType' => $mimetype, //text/plain',
'uploadType' => $uploadType
));
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
}
public function handleGoogleCallback()
{
return Redirect::to('home');
}
}