如何使用PHP将演示文稿文件上传到Google幻灯片?

编程入门 行业动态 更新时间:2024-10-11 05:27:48
本文介绍了如何使用PHP将演示文稿文件上传到Google幻灯片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用PHP将演示文件(ppt,pptx,pdf)上传到Google幻灯片服务.

How can I upload presentation file (ppt, pptx, pdf) to Google Slides service using PHP.

我没有在这些链接中找到示例:

I didn't find an example in these links:

developers.google/slides/quickstart/php

developers.google/api-client-library/php/support

我的代码:

$service = new Google_Service_Drive($client); $fileMetadata = new Google_Service_Drive_DriveFile([ 'name' => 'My Presentation', 'mimeType' => 'application/vnd.google-apps.presentation', // 'mimeType' => 'application/vnd.google-apps.document', ]); $file = $service->files->create($fileMetadata, [ 'data' => file_get_contents(realpath(dirname(__FILE__)) . '/Modelo_Slide_Padrao.pptx'), // 'mimeType' => 'application/vnd.ms-powerpoint', // 'application/pdf', 'uploadType' => 'multipart', 'fields' => 'id', ]); printf("File ID: %s\n", $file->id);

有人帮我吗?

谢谢.

推荐答案

您无法将演示文稿文件上传到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.

更多推荐

如何使用PHP将演示文稿文件上传到Google幻灯片?

本文发布于:2023-10-31 10:43:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545842.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   如何使用   文件上传   演示文稿   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!