1
votes

I'am using PHP Google Drive Api (Uploading files to Google Drive with PHP) to upload files on google drive and I want to know how to get the fileId after uploading, so I can use it as the SRC in HTML. Does someone knows? Thanks.

1
Welcome to stack. please edit your question include the code you are using and describe any issues you are having with that code. you may also want to read stackoverflow.com/help/how-to-askDaImTo

1 Answers

1
votes

You can find the answer to your question in examples from official Google's API PHP Client repository:

$file = new Google_Service_Drive_DriveFile();
$result = $service->files->create(
    $file,
    [
      'data' => file_get_contents('path/to/your/file'),
      'mimeType' => 'application/octet-stream',
      'uploadType' => 'media',
    ]
);

// $result->id is the ID you're looking for
// $result->name is the name of uploaded file

See the HTML example below, how you can use the $result object:

<a href="https://drive.google.com/open?id=<?= $result->id ?>" target="_blank"><?= $result->name ?>