Internet Explorer Content-DIsposition文件名不起作用

时间:2010-11-22 23:36:20

标签: php internet-explorer http-headers

现在我发送php(稍后用nodejs替换)文件下载的标题如下:

    <?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 / - 内容处置标题应该回复正确的文件名,但IE显示为文件名“123”和“未知文件类型”...现在即使我重写ID之后的所有文件夹index.php和请求例如:/download/123/something.exe它仍将显示为下载“某事”和“未知文件类型”。无论我设置为内容类型或我如何订购内容配置的值。

据我所知,这是一个从未得到解决的常见IE问题 - 有没有人知道解决这个问题?

谢谢!

编辑:只是为了确保每个人都知道我想要的正确结果:IE应该得到它的.EXE文件并提供“运行 - 保存 - 取消”对话框而不是“未知文件类型”标准“查找 - 保存 - 取消“对话框。顺便说一句。如果我点击查找它会将我重定向到微软页面,该页面向我解释x-msdownload是什么(现在设置为内容类型)......

1 个答案:

答案 0 :(得分:2)

Content-Disposition标头不完整,必须是:

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

Filename只是一个参数。如果要强制另存为对话框,也可以尝试attachment

MIME类型也不应该是application/octet-stream。 IIRC通常定义为application/x-msdos-program