需要有关google drive API的帮助。任何帮助,将不胜感激。在画布上绘制图像并保存到可以工作的文件夹,但我想从其保存路径获取该文件并将其上传到谷歌驱动器。以下是我的代码。我没有在upload.php中收到任何错误,但无法上传到谷歌驱动器,所以不确定我哪里出错了。
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);