Internet Explorer 无法在 PHP 应用程序中下载 rtf 文件

发布于 2024-12-08 15:36:10 字数 487 浏览 0 评论 0原文

我一如既往地遇到 ie8 问题。它不下载我通过脚本上传到服务器的 rtf 文件。它正确保存在数据库中

我的下载脚本是在 php 中

$outname = stripslashes($attachment[0]['dis_attach_content']);
$type = stripslashes($attachment[0]['dis_attach_type']);

$name = stripslashes($attachment[0]['dis_attach_name']);
header("Content-type:" . $type);

header('Content-disposition: attachment; filename=' . $name);
echo($outname);
exit;

这给出了错误:

在此处输入图像描述

I have a problem with ie8 As ALWAYS. its not downloading rtf files i uploaded to server by my script. its saving in the database correctly

My download script is in php

$outname = stripslashes($attachment[0]['dis_attach_content']);
$type = stripslashes($attachment[0]['dis_attach_type']);

$name = stripslashes($attachment[0]['dis_attach_name']);
header("Content-type:" . $type);

header('Content-disposition: attachment; filename=' . $name);
echo($outname);
exit;

This is giving the error:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘世孤行 2024-12-15 15:36:10

您可以尝试强制下载:

header("Content-Type: application/force-download");

注意;您应该考虑发送更多标头:

header("Pragma: public");
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Description: File Transfer');
header("Content-Type: $type");
header('Content-Length: ' . filesize($file));          
header('Content-Disposition: attachment; filename=' . basename($file));

You can try to force the download:

header("Content-Type: application/force-download");

Note; you should consider sending more headers:

header("Pragma: public");
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Description: File Transfer');
header("Content-Type: $type");
header('Content-Length: ' . filesize($file));          
header('Content-Disposition: attachment; filename=' . basename($file));
汐鸠 2024-12-15 15:36:10

将 Content-Disposition 标头设置为“attachment”,如下所示(在 PHP 中):附件是编写脚本的位置。

header('Content-Disposition: attachment');

并在 .htaccess 中添加以下内容,并添加您想要下载的扩展名,而不仅仅是 rtf

<FilesMatch "\.(rtf|txt|pdf|xls|xlsx|xlam|xlsb|xlsm|msg|doc|docx|mpg|jpg|png)">
   Header set Content-Disposition attachment
</FilesMatch>

Set the Content-Disposition header to "attachment", like so (in PHP): where attachment was scripted.

header('Content-Disposition: attachment');

and add the following in .htaccess and add what ever extension that you want to download not only rtf

<FilesMatch "\.(rtf|txt|pdf|xls|xlsx|xlam|xlsb|xlsm|msg|doc|docx|mpg|jpg|png)">
   Header set Content-Disposition attachment
</FilesMatch>
鸵鸟症 2024-12-15 15:36:10

这不太可能是 IE 的问题。

$name 输出到浏览器,并检查该 URL 是否准确指向您在服务器上查找的文件。

该 URL 是否与您的域完全一致?您可以使用确切的 URL 进行尝试,例如:http://website.com/file.rtf

This is unlikely to be a problem with IE.

Output $name to the browser, and check that this URL leads exactly to the file you're looking for on your server.

Is the URL exact to your domain? You could try it with the exact URL eg: http://website.com/file.rtf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文