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
", $file->id);