在 PHP
中是否有其他方式查看文件(本地/在线)?因为我想在我的浏览器中显示一个 .docx (.doc)
文件,但它一直在下载它。那么有人有代码吗?我继续搜索其他一些源代码,但没有运气。我尝试使用 Iframe
但仍然继续下载文件。谢谢!
最佳答案
使用 iframe 在浏览器中显示几乎所有类型文档的简单解决方案。
Solution is Google Docs Viewer
只需使用下面给出的 iframe
并替换其中文档的 url。
<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>
通过替换 .docx
文件的示例 url,上面的代码变成了。
<iframe src='https://docs.google.com/viewer?url=http://calibre-ebook.com/downloads/demos/demo.docx&embedded=true' frameborder='0'></iframe>
通过替换 .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 url and must be publicly available, because Google needs to fetch and display document, process fails if document is private and you will see iframe with NO PREVIEW AVAILABLE
关于php - 在浏览器上显示 .docx (.doc) 而无需在 php 中下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929920/