Chrome浏览器,不呈现不带扩展名的pdf文件 [英] Chrome, not rendering pdf file without extension

查看:726
本文介绍了Chrome浏览器,不呈现不带扩展名的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种情况我很难解释.当我在Internet Explorer中打开url时,我的URL以www ..../samplePDF.HTM格式结尾,它将页面读取为pdf(它并不关心.HTM的扩展名),但是当我打开Chrome中不会显示的相同网址,只会向我显示随机符号,就像无法对其进行加密一样.是否可以让chrome呈现内容并将网址识别为PDF文件.我无法将URL更改为samplePDF.PDF ...,但是如果将其保存在本地并将URL重命名为"samplePDF.PDF",则可以在计算机上以pdf格式打开它.我只需要能够在Chrome上打开它.感谢您的提前帮助.

I have this situation that is little bit hard to explain. I have this url that ends in this format of www..../samplePDF.HTM when I open the url in Internet Explorer, it reads the page as pdf (it doesnt care about the extension of .HTM), however when I open the same url in Chrome it wont render and just show me random symbols, like it cant encrypt it. is there away to have the chrome render the content and recognize the url as a PDF file. I cant change the url to samplePDF.PDF ... but if I save it locally and rename the url to "samplePDF.PDF" I can open it as pdf on my computer. I just need to be able to open it on the chrome. Thanks for the help in advance.

推荐答案

浏览器根据 MimeType解析文件服务器返回(在HTTP respnse标头中),而不是根据文件扩展名返回,当您提到它在IE上运行时,我感到很惊讶,因此我对其进行了测试,没错,就像IE试图解析如果未能根据MimeType继续解析数据,则下载数据本身,因此您可以将IE计为一个例外,大多数浏览器都不会这样做.

Browsers parse the files according to the MimeType the server returned (in the HTTP respnse headers), not according to the file extension, when you mentioned that it's working on IE I was surprised, so I tested it and you were right, it's like IE tries to parse the downloaded data itself if it failed to continue parsing according to the MimeType, so you can count IE an exception, most browsers don't do that.

对于您来说,我假设这是一个生成pdf的脚本文件,在这种情况下,您必须在脚本本身中提供MimeType,例如在php中,您可以将以下行放在脚本开头:

As for you, i assume that this is a script file that's generating a pdf, in which case you have to supply the MimeType in the script itself, for example in php you can put the following line at the start of the script:

header("Content-Type: application/pdf");

或者服务器上有一个现有文件,在这种情况下,网络服务器(Apache或IIS)试图自动将mime类型分配给该文件,则必须覆盖此文件.

or you have an existing file on the server, in which case the web-server (Apache or IIS) is trying to automatically assign mime type to the file, you have to override this.

例如,在Apache中,您可以在同一个文件夹中创建一个.htaccess文件,并在其中放置以下内容:

In Apache for example you can make a .htaccess file in the same folder and put something like this in it:

<Files samplePdf.htm>
    AddType application/pdf .htm
</Files>

这篇关于Chrome浏览器,不呈现不带扩展名的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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