PHP code example of uraymr / laravel-googledrive-ext

1. Go to this page and download the library: Download uraymr/laravel-googledrive-ext library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

uraymr / laravel-googledrive-ext example snippets


use Illuminate\Support\Facades\Storage;

// Upload a file
Storage::disk('google')->put('docs/example.txt', 'Hello from Laravel 12!');

return \Uraymr\GoogleDrive\Gdrive::previewFile('docs/example.txt');

'providers' => [
	// ...
	Uraymr\GoogleDrive\Providers\GoogleDriveServiceProvider::class,
],

'google' => [
	'driver' => 'google',
	'service_account' => env('GOOGLE_SERVICE_ACCOUNT_JSON', storage_path('app/google-service-account.json')),
	'folder_id' => env('GOOGLE_DRIVE_FOLDER_ID', 'root'),
],

'google' => [
	'driver' => 'google',
	'client_id' => env('GOOGLE_CLIENT_ID'),
	'client_secret' => env('GOOGLE_CLIENT_SECRET'),
	'refresh_token' => env('GOOGLE_REFRESH_TOKEN'),
	'folder_id' => env('GOOGLE_DRIVE_FOLDER_ID', 'root'),
],

use Illuminate\Support\Facades\Storage;

// Put a file
Storage::disk('google')->put('documents/report.pdf', $contents);

// Get contents
$contents = Storage::disk('google')->get('documents/report.pdf');

// Check exists
$exists = Storage::disk('google')->exists('documents/report.pdf');

// Delete
Storage::disk('google')->delete('documents/report.pdf');

use Uraymr\GoogleDrive\Gdrive;

// Upload
Gdrive::put('invoices/2025-10.pdf', $contents);

// Read
$contents = Gdrive::get('invoices/2025-10.pdf');

// Stream
$stream = Gdrive::readStream('invoices/2025-10.pdf');

// Metadata
$info = Gdrive::info('invoices/2025-10.pdf'); // size, mime_type, last_modified, path

// List directory
$items = Gdrive::list('/');

// Make directory
Gdrive::makeDirectory('backups');

// Download remote file to local path
Gdrive::download('invoices/2025-10.pdf', storage_path('app/invoices/2025-10.pdf'));