如何指定可下载文件的内容类型 [英] How to designate a downloadable file's content type

查看:95
本文介绍了如何指定可下载文件的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SO答案适用于我,但我不知道如何将内容类型更改为application/vnd.apple.pkpass"

This SO answer applies to me, but I don't know how to "change the content type to application/vnd.apple.pkpass"

当前直接指向我的pkpass的链接会触发下载,并且我不知道在哪里设置内容类型.

Currently a direct link to my pkpass triggers a download and I don't know where to set the content type.

我已要求托管服务提供商验证"application/vnd.apple.pkpass"是否为受支持的MIME类型

I have asked my hosting provider to verify that "application/vnd.apple.pkpass" is a supported MIME type

我尝试过

从iOS 6或Mac OS 10.8中单击链接时,如何做才能将文件识别为"application/vnd.apple.pkpass"?

What can I do to make the file recognized as the "application/vnd.apple.pkpass" when the link is clicked from iOS 6 or Mac OS 10.8?

推荐答案

您需要更改Web服务器的配置才能执行此操作.如何执行此操作取决于您所使用的Web服务器.如果您有托管公司为您管理站点服务器,则可能需要请他们这样做或告诉您可以在哪里进行.

You need to change the web server's configuration to do this. How you do this depends on which web server you're using. If you have a hosting company that manages your site's server for you, you likely need to ask them to do this or tell you where you can.

许多托管公司将Apache用作Web服务器.如果是这样,您可以在公共HTML目录中创建一个.htaccess文件,并将其放入其中:

Many hosting companies use Apache for the web server. If so, you can create a .htaccess file in your public HTML directory, and put this in it:

AddType application/vnd.apple.pkpass .pkpass

这将使所有以".pkpass"结尾的文件都使用该内容类型下载.

This will make any file that ends in ".pkpass" get downloaded with that content type.

这假设您要让客户端下载静态文件.如果要动态生成此文件,则完全不需要弄乱服务器,只需要发送一个标头即可.这取决于您使用的脚本语言,例如您将使用的PHP语言:

This assumes you're having the client download a static file. If you're dynamically generating this file, you don't need to mess with the server at all, and just need to send a header. This depends on which scripting language you're using, for example in PHP you'd do:

header("Content-Type: application/vnd.apple.pkpass");

这篇关于如何指定可下载文件的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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