PHP code example of yaza / laravel-google-drive-storage

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

    

yaza / laravel-google-drive-storage example snippets


 Storage::disk('google')->put($filename, File::get($filepath));

use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::put('location/filename.png', $request->file('file'));
// or
Gdrive::put('filename.png', public_path('path/filename.png'));
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

$data = Gdrive::get('path/filename.png');

return response($data->file, 200)
    ->header('Content-Type', $data->ext);

use Yaza\LaravelGoogleDriveStorage\Gdrive;

  $readStream = Gdrive::readStream('path/filename.png');

return response()->stream(function () use ($readStream) {
    fpassthru($readStream->file);
}, 200, [
    'Content-Type' => $readStream->ext,
    //'Content-disposition' => 'attachment; filename="'.$filename.'"', // force download?
]);
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

 $data = Gdrive::get('path/filename.png');
        return response($data->file, 200)
            ->header('Content-Type', $data->ext)
            ->header('Content-disposition', 'attachment; filename="'.$data->filename.'"');
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

 Gdrive::delete('path/filename.png');
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::deleteDir('foldername');
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::makeDir('foldername');
 
use Yaza\LaravelGoogleDriveStorage\Gdrive;

  Gdrive::renameDir('oldfolderpath', 'newfolder');

use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::all('/');
// or
Gdrive::all('foldername');

Illuminate\Support\Collection {#804 ▼ // app/Http/Controllers/UploadController.php:70
  #items: array:3 [▼
    0 => League\Flysystem\DirectoryAttributes {#798 ▶}
    1 => League\Flysystem\FileAttributes {#796 ▶}
    2 => League\Flysystem\DirectoryAttributes {#783 ▶}
  ]
  #escapeWhenCastingToString: false
}

use Yaza\LaravelGoogleDriveStorage\Gdrive;

Gdrive::all('/', true);
// or
Gdrive::all('foldername', true);

Illuminate\Support\Collection {#804 ▼ // app/Http/Controllers/UploadController.php:70
  #items: array:3 [▼
    0 => League\Flysystem\DirectoryAttributes {#798 ▶}
    1 => League\Flysystem\FileAttributes {#796 ▶}
    2 => League\Flysystem\DirectoryAttributes {#783 ▶}
  ]
  #escapeWhenCastingToString: false
}