文件强制下载

时间:2011-04-08 11:43:41

标签: php

我想强制下载..在IE中我收到错误但FF中没有问题

header("Content-Type: application/force-download\n");
header("Content-Disposition: attachment; filename=test.txt");

echo 'test file';

2 个答案:

答案 0 :(得分:5)

我只是搜索了你好奇的application/force-download mime类型。我不知道,谁做了“发明”这个,但似乎它只是不存在。见http://mimeapplication.org/force-download.html

这意味着,IE可能不喜欢它。请改用application/octet-stream。据我所知,firefox为每个mime类型打开一个下载对话框,可以使用“show download dialog”注册,也可以根本不知道。在这种情况下,FF可能不知道类型。

答案 1 :(得分:0)

这可能对你有帮助,对我有用

header('Content-Type: application/force-download');
header("Content-disposition: attachment; filename=$filename");
flush();
readfile($filename);
exit;

如果需要,您可以添加其他标题:)