1

Need help with the google drive API. Any help would be appreciated. An image is drawn on a canvas and saved to a folder which works but then i want to get that file from its save path and upload it to google drive. Below is my code. I don't get any errors in upload.php but cant upload to google drive so unsure where I'm going wrong.

save.php

   $data = $_POST['img'];
   $data = str_replace('data:image/png;base64,','',$data);
   $data = str_replace(' ','+',$data);

   $img = base64_decode($data);
   $path = 'images/'.uniqid().'.png';

   if(file_put_contents($path,$img))
   {
       print $path;
       require "upload.php";
   }
   else
   {
      header("HTTP 500 Internal Server Error");
   }

upload.php

$client->setClientId('');
$client->setClientSecret('');
$client>setRedirectUri('');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));


$fileMetadata = new Google_Service_Drive_DriveFile(array(
  'name' => 'photo.png'));
  $content = file_get_contents($path);
$file = $driveService->files->create($fileMetadata, array(
  'data' => $content,
  'mimeType' => 'image/png',
  'uploadType' => 'multipart',
  'fields' => 'id'));
printf("File ID: %s\n", $file->id); 
slukec
  • 11
  • 2
  • What doesn't work, what error do you get, what's the problem here? – Taha Paksu Apr 06 '17 at 20:24
  • the upload.php code doesnt work, i dont get any errors on it so im not sure where im going wrong. i am wondering if im missing something or need to change the code. – slukec Apr 06 '17 at 20:48

0 Answers0