PHP将文件上传到Google云端硬盘 [英] PHP upload a file on google Drive
问题描述
我正在学习Google驱动器API并从此文档中学习( https://developers.google.com/drive/v3/web/manage-uploads )中有一个代码示例,但是在代码中的某个地方,我发现了一些错误.
I am learning google drive API and from this documentation (https://developers.google.com/drive/v3/web/manage-uploads) there is a code example but somewhere in the code, I find something wrong.
这是Google api文档中的代码:
This is the code in the google api documentaiton:
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'photo.jpg'));
$content = file_get_contents('files/photo.jpg');
$file = $driveService->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'image/jpeg',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);
但是我不知道,这段代码是如何工作的,因为$ driveService之前没有初始化或为空
But I do not know, how this piece of code works since $driveService was not initialized before or it is null
$file = $driveService->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'image/jpeg',
'uploadType' => 'multipart',
'fields' => 'id'));
有人可以帮我吗.非常感谢你.
Can someone help me please. Thank you very much.
推荐答案
您忘记先阅读快速入门.
You forgot to read the quickstart first.
https://developers.google.com/drive/v3/web/quickstart/php
第3步是完整的PHP实施,服务为 $ service = new Google_Service_Drive($ client);
Full PHP Implement is in step 3 and the service is $service = new Google_Service_Drive($client);
这篇关于PHP将文件上传到Google云端硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!