Reputation: 11
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.
Upvotes: 1
Views: 1996
Reputation: 2380
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 ?>
Upvotes: 1