在浏览器上显示 .docx (.doc) 而无需在 php 中下载 [英] Display .docx (.doc) on Browser without downloading in php

查看:115
本文介绍了在浏览器上显示 .docx (.doc) 而无需在 php 中下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 中有没有其他方法可以查看文件(本地/在线)?因为我想在我的浏览器中显示一个 .docx (.doc) 文件,但它一直在下载它.那么有人有这方面的代码吗?我继续搜索其他一些源代码,但没有运气.我尝试使用 Iframe 但仍然继续下载文件.谢谢!

解决方案

使用 iframe 在浏览器中显示几乎所有类型的文档的简单解决方案.

<块引用>

解决方案是 Google 文档查看器

只需使用下面给出的 iframe 并替换其中的文档 url.

<iframe src='https://docs.google.com/viewer?url=在此处输入您的文档的 URL&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文件的示例网址,上面的代码变成了.

<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>

<块引用>

注意:需要在浏览器中显示的文档必须正确url 并且必须公开,因为 Google 需要获取并显示文档,如果文档是私有的,则过程失败您会看到 iframeNO PREVIEW AVAILABLE

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 Iframe but still keeps on downloading the file. Thanks!

解决方案

An easy solution to display almost every type of document in browser using iframe.

Solution is Google Docs Viewer

Just use iframe as given below and replace url of document in it.

<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>

By Replacing sample url for .docx file, above code becomes.

<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 .pdf file, above code becomes.

<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

这篇关于在浏览器上显示 .docx (.doc) 而无需在 php 中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆