更新时间:2021-09-04 22:09:44
您无法将演示文稿文件上传到Google幻灯片.您需要执行的操作是使用Google文档类型将文件导入Google云端硬盘.看看 参考文档 其中有一个如何实现此目的的示例.以下是如何实现所需需求的示例.
You cannot upload a presentation file to Google Slides. What you are required to do is to import the file to Google Drive using a Google Doc Type. Take a look at the reference documentation which has an example of how to achieve this. Here are the examples of how to achieve what you need.
PPT到Google幻灯片演示文稿:
$service = new Google_Service_Drive($client);
// Create a new file
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PPT Test Presentation',
'mimeType' => 'application/vnd.google-apps.presentation'
));
// Read power point ppt file
$ppt = file_get_contents("SamplePPT.ppt");
// Declare optional parameters
$optParams = array(
'uploadType' => 'multipart',
'data' => $ppt,
'mimeType' => 'application/vnd.ms-powerpoint'
);
// Import pptx file as a Google Slide presentation
$createdFile = $service->files->create($file, $optParams);
// Print google slides id
print "File id: " . $createdFile->id;
PPTX到Google幻灯片演示文稿:
$service = new Google_Service_Drive($client);
// Create a new file
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PPTX Test Presentation',
'mimeType' => 'application/vnd.google-apps.presentation'
));
// Read Powerpoint pptx file
$pptx = file_get_contents("SamplePPTX.pptx");
// Declare opts params
$optParams = array(
'uploadType' => 'multipart',
'data' => $pptx,
'mimeType' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
);
// Import pptx file as a Google Slide presentation
$createdFile = $service->files->create($file, $optParams);
// Print google slides id
print "File id: " . $createdFile->id;
PDF到Google Document Doc :(对于Google Slide Presentation而言是不可能的)
$service = new Google_Service_Drive($client);
// Create a new file
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PDF Test Document',
'mimeType' => 'application/vnd.google-apps.document'
));
// Read pdf file
$pdf = file_get_contents("SamplePDF.pdf");
// Declare opts params
$optParams = array(
'uploadType' => 'multipart',
'data' => $pdf,
'mimeType' => 'application/pdf'
);
// Import pdf file as a Google Document File
$createdFile = $service->files->create($file, $optParams);
// Print google document id
print "File id: " . $createdFile->id;
每个代码段中唯一更改的是mimeType
.有关Mime类型的参考,您可以访问此处,然后有关Google Mime类型的参考,您可以在此处访问.
The only thing that changes in each code snippet is the mimeType
. For a reference of Mime Types you can visit here and for a reference of Google Mime Types you can visit here.