PHP code example of jeffersongoncalves / flysystem-google-drive

1. Go to this page and download the library: Download jeffersongoncalves/flysystem-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/ */

    

jeffersongoncalves / flysystem-google-drive example snippets


// config/filesystems.php
'disks' => [
    'google-drive' => [
        'driver' => 'google-drive',
        'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
        'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
        'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
        'folder' => env('GOOGLE_DRIVE_FOLDER'), // optional: a Drive folder ID or name to scope everything under
    ],
],

Storage::disk('google-drive')->put('backups/db.sql.gz', $contents);

use Google\Client;
use Google\Service\Drive;
use JeffersonGoncalves\FlysystemGoogleDrive\GoogleDriveAdapter;
use League\Flysystem\Filesystem;

// Either build the adapter directly from credentials...
$adapter = GoogleDriveAdapter::fromCredentials(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    refreshToken: 'your-refresh-token',
    folder: 'Backups', // optional
);

// ...or hand it an already-configured \Google\Service\Drive (e.g. to inject a mock in tests).
$client = new Client();
$client->setClientId('your-client-id');
$client->setClientSecret('your-client-secret');
GoogleDriveAdapter::useRefreshTokenLazily($client, 'your-refresh-token');
$adapter = new GoogleDriveAdapter(new Drive($client), folder: 'Backups');

$filesystem = new Filesystem($adapter);
$filesystem->write('backups/db.sql.gz', $contents);