http://localhost:3422/wordpress/wp-content/plugins/mktProc/google-api-php-client/gDrive_access/pdf_results_upload.php
http://hyperAd.com/wp-content/plugins/mktProc/google-api-php-client/gDrive_access/pdf_results_upload.php
if(!session_id()){session_start();}
require_once realpath(dirname(__FILE__) . '/../autoload.php');
$credentialsPath = realpath(dirname(__FILE__) . '/../../../../../');
$pdf_filename=''; try { if(isset($_SESSION['pdf_filename']) && $_SESSION['pdf_filename'])
$pdf_filename=$_SESSION['pdf_filename']; }
catch(Exception $ex)
{ echo ("This is for GDrive Upload from MiniROI"); }
$pfdStoragePath=dirname(__FILE__)."/../../vendor/pdf/".$pdf_filename;
/************************************************ ATTENTION: Fill in these values! Make sure the redirect URI is to this page, e.g: http://localhost:8080/fileupload.php ************************************************/
$client_id = '374094698471-5.apps.googleusercontent.com';
$client_secret = 'd374094698471y';
$redirect_uri = 'http://localhost:3422/wordpress/wp-content/plugins/miniROIMarketo/google-api-php-client/gDrive_access/roi_results_upload.php';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setAccessType("offline"); //$client->setApprovalPrompt('force');
$service = new Google_Service_Drive($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['upload_token']); }
$accessToken=""; //log $plugin_dir ='../../vendor/pdf/log.txt';
$accessFilePath=$credentialsPath.'\miniROIAccessToken.json';
if (file_exists($accessFilePath)) {
$accessToken = json_decode(file_get_contents($accessFilePath), true); }
elseif (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$accessToken = $client->getAccessToken();
file_put_contents($credentialsPath.'\miniROIAccessToken.json', json_encode($accessToken));
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); }
if ($accessToken) { $client->setAccessToken($accessToken);
if ($client->isAccessTokenExpired()) { unset($accessToken); } }
else { $authUrl = $client->createAuthUrl(); }
/************************************************ If we're signed in then lets try to upload our file. ************************************************/
try { if ($client->getAccessToken()) {
if($pdf_filename!=="") {
$file = new Google_Service_Drive_DriveFile();
$file->setTitle($pdf_filename);
$file->setDescription('Document');
$file->setMimeType('application/pdf');
$result = $service->files->insert( $file, array( 'data' => file_get_contents($pfdStoragePath), 'mimeType' => 'application/pdf', 'uploadType' => 'multipart' ) );
$pdf_filename=""; unset($_SESSION['pdf_filename']); } } }
catch (Exception $ex) { echo "Unexpected issue encountered. Please Try again later."; }
?>
Attachment: gDrive_upload.zip