Internet Explorer Content-Disposition文件名不起作用。

3

现在我正在使用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)...


FYI - 我在OSX上运行,目前在crossover中运行IE7,但我已经确认了同事使用运行IE7的Windows桌面和另一个运行IE8的人都有相同的结果。 - Toby
1个回答

2

Content-Disposition头不完整,必须为:

 header("Content-Disposition: inline; filename=xyz.exe");

文件名只是一个参数。如果您想强制使用“另存为”对话框,也可以尝试attachment

此外,MIME类型不应该是application/octet-stream。我记得通常定义为application/x-msdos-program


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接