PHP code example of fnsc / laravel-google-drive

1. Go to this page and download the library: Download fnsc/laravel-google-drive 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/ */

    

fnsc / laravel-google-drive example snippets


use LaravelGoogleDrive\GoogleDrive;
use Illuminate\Http\Request;

Route::post('/upload', function (Request $request, GoogleDrive $drive) {
    $result = $drive->upload($request->file('file'));

    return [
        'file_id'   => $result->getFileId(),
        'file_name' => $result->getFileName(),
        'folder_id' => $result->getFolderId(),
    ];
});

$drive->upload($request->file('file'), 'your_folder_id');

$results = $drive->uploadMany($request->file('files'));

use Illuminate\Http\Response;

Route::get('/download', function (GoogleDrive $drive) {
    $file = $drive->get('filename.pdf', 'google_drive_file_id');

    return new Response($file->getContent(), 200, [
        'Content-Type'        => $file->getMimeType(),
        'Content-Disposition' => 'attachment; filename=' . $file->getName(),
    ]);
});

$deleted = $drive->delete('google_drive_file_id'); // returns bool
bash
php artisan vendor:publish --provider="LaravelGoogleDrive\ServiceProvider"