tbetool / google-drive-manager
此包的最新版本(1.1)没有提供许可信息。
基于Google PHP SDK。启用对Google Drive的上传和下载功能。
1.1
2018-06-20 09:07 UTC
Requires
- php: >=5.5
- google/apiclient: ^2.0
This package is auto-updated.
Last update: 2024-09-08 17:27:27 UTC
README
Google Drive Manager
安装
composer require tbetool/google-drive-manager
所需权限
https://www.googleapis.com/auth/drive
初始化
$drive = new GoogleDriveManager('client_id', 'client_secret', 'access_token');
设置访问令牌
$drive->setAccessToken('access_token');
列出文件夹中的条目
$response = $drive->listFolder();
响应
响应将包含
[
(int) 0 => [
'id' => '1YoSEbFDSOejkZmtPmfOyBIoWODhllPjJ',
'name' => 'Selling Digital Items Modules to be updated ',
'kind' => null,
'type' => 'folder',
'created_time' => null,
'file_extension' => null,
'mime_type' => null,
'modified_time' => null,
'original_filename' => null,
'size' => null
],
]
搜索条目
$drive->search('query');
响应
[
(int) 0 => [
'id' => '1YoSEbFDSOejkZmtPmfOyBIoWODhllPjJ',
'name' => 'Selling Digital Items Modules to be updated ',
'kind' => null,
'type' => 'folder',
'created_time' => null,
'file_extension' => null,
'mime_type' => null,
'modified_time' => null,
'original_filename' => null,
'size' => null
],
]
下载文件
目前处于开发中
$drive->download('item_id', $save_to_path);
save_to_path 应为保存文件的绝对本地路径
响应
[
'id' => '1lJNyeIx5BpyK88Vj31YFG6WVVNY_g9Hj',
'name' => 'file.zip',
'kind' => 'drive#file',
'type' => 'application/zip',
'created_time' => null,
'file_extension' => null,
'mime_type' => 'application/zip',
'modified_time' => null,
'original_filename' => null,
'size' => null,
'download_path' => '/home/path/to/local/save/to/file.zip'
]
创建文件夹
$drive->createFolder('folder name', $parent_folder_id);
如果没有提供 $parent_folder_id,文件夹将创建在根文件夹中
[
'id' => '1Q6fozdc2JK32HO2nimSKz1lQ0AVxl413',
'name' => 'New Folder 123',
'kind' => 'drive#file',
'type' => 'folder',
'created_time' => null,
'file_extension' => null,
'mime_type' => 'application/vnd.google-apps.folder',
'modified_time' => null,
'original_filename' => null,
'size' => null
]
将文件上传到文件夹
$drive->upload('file/path/', $folder_id);
file_path 必须是本地文件的绝对路径
如果没有提供 folder_id,文件将上传到根文件夹
响应
[
'id' => '1Q6fozdc2JK32HO2nimSKz1lQ0AVxl413',
'name' => 'New Folder 123',
'kind' => 'drive#file',
'type' => 'folder',
'created_time' => null,
'file_extension' => null,
'mime_type' => 'application/vnd.google-apps.folder',
'modified_time' => null,
'original_filename' => null,
'size' => null
]
将文件移动到另一个文件夹
$drive->move($file_id, $folder_id);
需要提供 file_id 和 folder_id。
响应
[
'id' => '1Q6fozdc2JK32HO2nimSKz1lQ0AVxl413',
'name' => 'New Folder 123',
'kind' => 'drive#file',
'type' => 'folder',
'created_time' => null,
'file_extension' => null,
'mime_type' => 'application/vnd.google-apps.folder',
'modified_time' => null,
'original_filename' => null,
'size' => null
]