现在我正在使用PHP(稍后将替换为Node.js)发送文件下载的标头,如下所示:
<?php
// example array for .exe (for IE, doesnt work)
// i also tried x-msdownload
$file = array( 'octet-stream', 'download.exe' );
header( 'HTTP/1.0 200 OK' );
header( 'Content-Type: application/'.$file[0] );
// thats the part that doesnt work - i tried inline; attachment; with quotes, without quotes, single quotes, ending ; no ending ;...
header( 'Content-Disposition: filename="'.$file[1].'";' );
header( 'Content-Length: '.filesize( $file[1] ) );
readfile( $file[1] );
exit;
?>
结果总是相同的 - 我将下载重写到一个文件夹中,如下所示:/download/123/ - content-disposition标题应该回复正确的文件名,但IE显示为文件名“123”和“未知文件类型”...现在即使我将ID后的所有内容重写到文件夹index.php并请求例如:/download/123/something.exe,它仍将显示为下载“something”和“未知文件类型”。不管我设置什么作为content-type或者我如何排列content-disposition的值。
据我所了解,这是一个常见的IE问题,从未得到修复 - 有人知道这个问题的解决方法吗?
谢谢!
编辑:只是为了确保每个人都知道我想要的正确结果:IE应该知道这是一个.EXE文件,并提供“运行-保存-取消”对话框,而不是“未知文件类型”的标准“查找-保存-取消”对话框。顺便说一句,如果我点击查找,它会重定向到微软页面,解释x-msdownload是什么(它现在被设置为content-type)...