zlt / php-google-drive
Easy-To-Use PHP Library For Google Drive
Fund package maintenance!
www.buymeacoffee.com/zawlintun
Installs: 271
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/zlt/php-google-drive
Requires
- google/apiclient: ^2.12
This package is auto-updated.
Last update: 2025-10-13 08:41:02 UTC
README
-
Installation
$ composer require zlt/php-google-drive
-
Setup
$clientId = 'clientId'; $clientSecret = 'clientSecret'; $refreshToken = 'refreshToken'; $config = new GoogleDriveConfig(clientId: $clientId, clientSecret: $clientSecret, refreshToken: $refreshToken); $service = new GoogleDriveService($config);
If you don't know how to find the credentials i.e, clientId, clientSecret, refreshToken, read here.
-
Usage
-
Creating Content
Use
putmethod which accepts three parameters:content- contents to be storedfileName- filename of content to be storeddir- If not specified, file will be stored under root. Otherwise, file will be stored under specifed dir.
$service->put('This is example text', 'example.txt'); $service->put('This is text will be stored under specified dir','example.txt','12sdf_sdfjopwoeriupsdf')
-
Getting File
Use
getmethod which accepts two parameters and returnGoogle\Drive\DriveFileorGuzzleHttp\Psr7\ResponsefileName- filename of content to be storedparams- If not specified, empty array is passed.
$service->get('xxxxxxxxxxxxx'); // or $service->get('xxxxxxxxxxxxx', [ // pass parameters ])
-
Getting File Content
Use
getContentmethod which returnGuzzleHttp\Psr7\Response.fileName- filename of content to be stored
$service->getContent('xxxxxxxxxxxxx');
-
Creating Dir
Use
makeDirectorywhich accepts two parameters:folderName- folderNamedir- If not specified, folder will be created under root. Otherwise, folder will be created under specifed dir.
$service->makeDirectory('New Folder'); $service->makeDirectory('New Folder Under Specified Dir','12sdf_sdfjopwoeriupsdf')
-
Copy File
Use
copywhich accepts three parameters:fromId- fileIdfileName- fileNamedir- If not specified, folder will be created under root. Otherwise, folder will be created under specifed dir.
$service->copy('1kojo32uoiuo123','new file.txt'); $service->copy('1kojo32uoiuo123','new file.txt','12sdf_sdfjopwoeriupsdf')
-
List Contents
Use
listContentsmethod which accepts two parameters:pathwhich is either pathId, fileName, folderName ,andrecursivewhich decide to show children contents.// List files inside root dir. $service->listContents() // List files inside 'shared with me' folder. $service->listContents(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
-
List Directories
Use
directoriesmethod which accepts two parameters:pathwhich is either pathId, fileName, folderName// List files inside root dir. $service->directories() // List files inside 'shared with me' folder. $service->directories(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
-
List Files
Use
filesmethod which accepts two parameters:pathwhich is either pathId, fileName, folderName// List files inside root dir. $service->files() // List files inside 'shared with me' folder. $service->files(Zlt\PhpGoogleDrive\GoogleDriveService::SharedWithMe);
-
Delete File or Folder
Delete file
$service->delete('fileId')