如果文件由 php 脚本提供,如何使用 google 文档查看器在网页上嵌入 ppt 文件?
我已将 MS powerpoint 文件上传到我的服务器,并尝试使用 Google 文档查看器 (http://docs.google.com/viewer) 将其显示在网页上。 该文件可在此处获取: http://elgg.wamped.org/test.ppt
如果我使用以下命令调用文档查看器上面的 URL,它按预期工作,请参阅: http://docs.google.com /viewer?url=http%3A%2F%2Felgg.wamped.org%2Ftest.ppt
但是,当我尝试通过一个非常简单的 php 脚本向查看器提供同一文件时,它无法渲染不太有用的错误消息:“抱歉,我们此时无法生成文档的视图”,请参阅: http://docs.google.com /viewer?url=http%3A%2F%2Felgg.wamped.org%2Freadfile.php
提供该文件的脚本如下:
<?php
header('Content-type: application/vnd.ms-powerpoint');
header('Content-Disposition: attachment; filename="test.ppt"');
readfile('test.ppt');
?>
我尝试过使用各种标头字段,例如 Pragma 和 Cache-Control ,但没有任何帮助。我还尝试对输出文件进行切片并以块形式回显,但这也没有任何好处。检查了服务器上的 apache 日志,检查了响应标头,对我来说一切都很好。
有什么想法我在这里做错了什么吗?
编辑:虽然我还没有找到此问题的解决方案,但我偶然发现了一个与 Google 文档查看器具有相同功能(或者实际上似乎比该功能更多)的网站。 http://embedit.in 支持多种文件类型,有 API,并且做得很好,所以我可能会选择那个。然而,出于好奇,我仍然想知道下面这段代码有什么问题。因此,任何建议都非常受欢迎。
I've uploaded an MS powerpoint file to my server, and I'm trying to use Google Docs viewer (http://docs.google.com/viewer) to display it on a webpage.
The file is available here:
http://elgg.wamped.org/test.ppt
If I invoke the docs viewer with the above URL, it is working as expected, see:
http://docs.google.com/viewer?url=http%3A%2F%2Felgg.wamped.org%2Ftest.ppt
But when I'm trying to serve the same file through a very simple php script to the viewer, it fails rendering with the not too helpful error message: "Sorry, we are unable to generate a view of the document at this time", see:
http://docs.google.com/viewer?url=http%3A%2F%2Felgg.wamped.org%2Freadfile.php
The script that serves the file is as follows:
<?php
header('Content-type: application/vnd.ms-powerpoint');
header('Content-Disposition: attachment; filename="test.ppt"');
readfile('test.ppt');
?>
I've tried playing around with various header fields like Pragma and Cache-Control, but nothing helped. I also tried slicing the output file and echoing in chunks, that also did not do any good. Checked the apache log on the server, checked the response headers, everything seems fine to me.
Any ideas what am I doing wrong here?
EDIT: Although I haven't found a solution to this issue, I stumbled upon a site that does the same (or seems to do more than that, actually) as Google Docs Viewer. http://embedit.in has support for a wide range of file types, has an API, and does the job nicely, so I'll just probably go with that one. However, out of curiousity, I'd still like to know what is wrong with the piece of code below. So any suggestions are more than welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过使用 .ppt 文件扩展名而不是 .php 来命名 php 文件?您的服务器是否会处理没有 .php 文件扩展名的文件中的 php 代码是另一个问题。但 Google 文档可能会拒绝加载任何带有 .php 扩展名的文件。
Have you tried naming the php file with a .ppt file extension instead of .php? Whether or not your server will process php code in a file that doesn't have a .php file extension is another problem. But Google Docs may simply say NO to loading any file with a .php extension on it.
Content-Type 中的 T 大写。我还提供了 Content-Length 标头。我的文件处理程序现在可以工作了。
Capitalize the T in Content-Type. I also provided the Content-Length header. My filehandler works now.
看来您可能缺少一些标头。您可能还想查看该文件是否与 readfile.php 位于同一目录中,因为 google 可能将每个文件存储在远程服务器上。
It looks like you might be missing some headers. You might also want to see if the file is in the same directory as readfile.php, because google might store each file on a remote server.