如何将文件上载到google drive中的特定文件夹-google drive API(PHP)
如何将文件上载到google drive-google drive API中的特定文件夹? 我有这个代码,它把我的文件上传到谷歌硬盘的主文件夹如何将文件上载到google drive中的特定文件夹-google drive API(PHP),php,google-drive-api,Php,Google Drive Api,如何将文件上载到google drive-google drive API中的特定文件夹? 我有这个代码,它把我的文件上传到谷歌硬盘的主文件夹 $client->setAccessToken($_SESSION['accessToken']); $service = new Google_DriveService($client); $finfo = finfo_open(FILEINFO_MIME_TYPE); $file = new Google_DriveFile(); foreac
$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
));
}
下面是如何在V3中实现的。这称为“设置父级”,因为一旦文件位于文件夹中,它也将继承其所在父级的共享选项 下面两行将设置文件名,然后setParents将定义要将文件放入的文件夹。参数是数组,但不要放置超过1项,否则会出现错误:
$file->setName("world");
$file->setParents(['SOME_UNIQUE_FOLDER_ID']);
您好,您必须使用父文件夹ID数组设置
parents
属性(有关文件创建,请参阅此处的属性列表)