简体   繁体   English

如何使文件扩展名可下载?

[英]How to make a file extension downloadable?

I'm trying to download http://www.downway1.com/dota/eng/DotA%20Allstars%20v6.67.w3x this file. 我正在尝试下载http://www.downway1.com/dota/eng/DotA%20Allstars%20v6.67.w3x此文件。 But it's not able to download. 但是它无法下载。 It's opening unknown text. 它正在打开未知文本。 How I can set it up? 我该如何设置? Maybe I can use htaccess? 也许我可以使用htaccess? but how ? 但是如何?

I can download it with google chrome and opera, so probably it's a browser related issue. 我可以使用Google chrome和Opera来下载它,所以可能是与浏览器有关的问题。 Anyway, add to your .htaccess the following : 无论如何,将以下内容添加到您的.htaccess中:

AddType application/octet-stream .w3x

you can also make use of headers: 您还可以使用标题:

<?php
 // outputting the file
 header('Content-type: application/octet-stream');

 // It will be called DotA Allstars v6.67.w3x
 header('Content-Disposition: attachment; filename="DotA Allstars v6.67.w3x"');

 // The source file
 readfile('DotA Allstars v6.67.w3x');
?>

Use the AddType directive to set the type for the .w3x file extension: 使用AddType指令设置.w3x文件扩展名的类型:

AddType application/octet-stream .w3x

The application/octet-stream media type is defined to describe arbitrary binary data and clients should not open it directly but download it. 定义应用程序/八位字节流媒体类型以描述任意二进制数据,客户端不应直接打开它,而应下载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM