在浏览器上显示 .docx (.doc) 而无需在 php 中下载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20929920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display .docx (.doc) on Browser without downloading in php
提问by leonardeveloper
Is there any alternative way of viewing a file(locally/online) in PHP? Since I want to display a .docx (.doc)file in my browser but it keeps on downloading it. So anyone who has a code for that? I keep on searching some other source code but no luck. I tried using Iframebut still keeps on downloading the file. Thanks!
有没有其他方法可以查看文件(本地/在线)PHP?因为我想.docx (.doc)在我的浏览器中显示一个文件,但它一直在下载它。那么有人有这方面的代码吗?我继续搜索其他一些源代码,但没有运气。我尝试使用Iframe但仍然继续下载文件。谢谢!
回答by Aamir
After a lot research i found a best solution to display almost every type of document in browser using iframe.
经过大量研究,我找到了使用 iframe 在浏览器中显示几乎所有类型文档的最佳解决方案。
Solution is Google Docs Viewer
解决方案是Google Docs Viewer
Just use iframeas given below and replace url of document in it.
只需使用iframe如下所示并替换其中的文档 url。
<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>
By Replacing sample url for .docxfile, above code becomes.
通过替换.docx文件的示例 url ,上面的代码变为。
<iframe src='https://docs.google.com/viewer?url=http://calibre-ebook.com/downloads/demos/demo.docx&embedded=true' frameborder='0'></iframe>
By Replacing sample url for .pdffile, above code becomes.
通过替换.pdf文件的示例 url ,上面的代码变为。
<iframe src='https://docs.google.com/viewer?url=http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf&embedded=true' frameborder='0'></iframe>
Note: Document that you need to display in browser must have correct urland must be publicly available, because Google needs to fetch and display document, process fails if document is private and you will see iframewith NO PREVIEW AVAILABLE
注:文件,你需要在浏览器中显示必须有正确的网址,并且必须是公开可用的,因为谷歌需要获取和显示文件,如果文件是私有的,你会看到进程失败的iframe与NO预览可用
回答by afaf12
I have viewed some MS Office documents on www.dropbox.com. I just had a look, the tool used is called QuickLook Framework. It converts docx/doc to pdf and displays the pdf document on the website. But it is an iOS library.
我在www.dropbox.com上查看了一些 MS Office 文档。我刚看了一下,使用的工具叫做QuickLook Framework。它将 docx/doc 转换为 pdf 并在网站上显示 pdf 文档。但它是一个iOS库。
If your documents are public, you could use Office web vieweror Google Docs viewer.
如果您的文档是公开的,您可以使用Office web 查看器或Google Docs 查看器。
I have never used PHP to view Word documents online and have never seen a complete tool for that. But writing a parser is definitely possible, the question is - how much of the formatting do you want to retain? If losing formatting is acceptable, you could try starting with answers from similarquestions.
我从未使用 PHP 在线查看 Word 文档,也从未见过完整的工具。但是编写解析器绝对是可能的,问题是 - 你想保留多少格式?如果可以接受丢失格式,您可以尝试从类似问题的答案开始。
回答by Hamza Saleem
I don't know if this thread is closed or what but for google view this code works prefectly
我不知道此线程是否已关闭或什么但对于谷歌查看此代码完全有效
<iframe src='//docs.google.com/gview?url=URLOFDOC.docx&embedded=true' frameborder='0'></iframe>

