PHP code example of zlt / php-google-drive

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

    

zlt / php-google-drive example snippets


  $clientId = 'clientId';
  $clientSecret = 'clientSecret';
  $refreshToken = 'refreshToken';
  $config = new GoogleDriveConfig(clientId: $clientId, clientSecret: $clientSecret, refreshToken: $refreshToken);
  $service = new GoogleDriveService($config);
  

  $service->put('This is example text', 'example.txt');
  
  $service->put('This is text will be stored under specified dir','example.txt','12sdf_sdfjopwoeriupsdf')
  

  $service->get('xxxxxxxxxxxxx');

  // or

  $service->get('xxxxxxxxxxxxx', [
    // pass parameters
  ])
  

  $service->getContent('xxxxxxxxxxxxx');
  

  $service->makeDirectory('New Folder');
    
  $service->makeDirectory('New Folder Under Specified Dir','12sdf_sdfjopwoeriupsdf')
  

  $service->copy('1kojo32uoiuo123','new file.txt');
    
  $service->copy('1kojo32uoiuo123','new file.txt','12sdf_sdfjopwoeriupsdf')
  

    // List files inside root dir.
    $service->listContents()
  
    // List files inside 'shared with me' folder.
    $service->listContents(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
  

    // List files inside root dir.
    $service->directories()
  
    // List files inside 'shared with me' folder.
    $service->directories(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
  

    // List files inside root dir.
    $service->files()
  
    // List files inside 'shared with me' folder.
    $service->files(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
  

    $service->delete('fileId')
    
bash
  $ composer