php ie9自动下载

发布于 2024-11-09 07:55:01 字数 1248 浏览 0 评论 0原文

大家好,我正在尝试在人们访问页面时显示一个自动下载框。 我已经在所有浏览器上都可以使用这个功能,现在 ie9 已经出现了,虽然它在最后下载,但它说“此下载被中断”,

这就是我正在使用的代码明智的

// set headers
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
    header( 'Content-Description: File Transfer' );
    header("Content-Type: ".$mtype);
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".(string)$size.";\n");


    //get a chunk of the file
    $chunksize = 1*(1024*1024); // how many bytes per chunk
    $buffer = '';

     //downloads file
    $handle = fopen($download_file, 'rb');
    if ($handle === false) {
    }
    //write to the browser for download
    while (!feof($handle)) {
     $buffer = fread($handle, $chunksize);
     echo $buffer;
     ob_flush();
     flush();
     if ($retbytes) {
       $cnt += strlen($buffer);
     }
    }
    exit;

任何想法吗?

Hi guys I'm trying to get an automatic download box to appear when people go a page.
I've got this working on all the browsers and now ie9 has come along and although it downloads at the end it says "This download was interrupted"

this is what I'm using code wise

// set headers
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
    header( 'Content-Description: File Transfer' );
    header("Content-Type: ".$mtype);
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".(string)$size.";\n");


    //get a chunk of the file
    $chunksize = 1*(1024*1024); // how many bytes per chunk
    $buffer = '';

     //downloads file
    $handle = fopen($download_file, 'rb');
    if ($handle === false) {
    }
    //write to the browser for download
    while (!feof($handle)) {
     $buffer = fread($handle, $chunksize);
     echo $buffer;
     ob_flush();
     flush();
     if ($retbytes) {
       $cnt += strlen($buffer);
     }
    }
    exit;

Any ideas?

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

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

发布评论

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

评论(1

只为一人 2024-11-16 07:55:01

我只是使用 readfile 代替您正在执行的有些复杂的文件输出:

// set headers
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
header( 'Content-Description: File Transfer' );
header("Content-Type: ".$mtype);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)$size.";\n");

readfile($download_file);
exit;

看看是否可以作品。

Instead of the somewhat complicated file output you're doing, I'd just use readfile instead:

// set headers
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
header( 'Content-Description: File Transfer' );
header("Content-Type: ".$mtype);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)$size.";\n");

readfile($download_file);
exit;

See if that works.

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