MiksMeister
MiksMeister

Reputation: 428

PHP upload a file on google Drive

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.

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);

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.

Upvotes: 0

Views: 5917

Answers (1)

Huy Trịnh
Huy Trịnh

Reputation: 753

You forgot to read the quickstart first.

https://developers.google.com/drive/v3/web/quickstart/php

Full PHP Implement is in step 3 and the service is $service = new Google_Service_Drive($client);

Upvotes: 1

Related Questions