小编Shi*_*lat的帖子

如何将文件上传到谷歌驱动器中的特定文件夹 - Google 驱动器 API (PHP)

如何将文件上传到 google drive -Google drive API 中的特定文件夹?我有这个代码,它将我的文件上传到谷歌驱动器中的主文件夹。

$client->setAccessToken($_SESSION['accessToken']);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
foreach ($files as $file_name) {
    $file_path = 'files/'.$file_name;
    $mime_type = finfo_file($finfo, $file_path);
    $file->setTitle($file_name);
    $file->setDescription('This is a '.$mime_type.' document');
    $file->setMimeType($mime_type);
    $service->files->insert($file, array(
        'data' => file_get_contents($file_path),
         'mimeType' => $mime_type
    ));
}
Run Code Online (Sandbox Code Playgroud)

php google-drive-api

5
推荐指数
1
解决办法
593
查看次数

标签 统计

google-drive-api ×1

php ×1