php - 在浏览器上显示 .docx (.doc) 而无需在 php 中下载

标签 php ms-word .doc

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/

相关文章:

javascript - 使用 JS 下载 <div> 到 .doc 或 .docx

PHP:检查进程是否正在使用 pid 运行

php - php array_multisort 是如何工作的?

php - Log_message 代码点火器

c# - 从 Word 中获取 RTF

PHP - 从上传的 Microsoft Word 文档中获取字数

python-3.x - 将Jupyter Notebook转换成MS Word文档.doc?

php - 显示SQL查询中修改的数据

r - 使用ReporteRs将lmer摘要信息输出到word

php - 是否有适用于 Microsoft Word 的嵌入式可视化 (PHP) 解析器?