首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php ie9自动下载

php ie9自动下载
EN

Stack Overflow用户
提问于 2011-05-25 18:47:56
回答 1查看 745关注 0票数 0

大家好,我正在尝试让一个自动下载框出现时,人们去一个页面。我已经让它在所有浏览器上都能工作了,现在ie9出现了,虽然它在最后下载了,但它显示“这个下载被中断了”。

这就是我使用的代码智慧

代码语言:javascript
复制
// 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;

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-25 18:53:51

我没有使用您正在做的有点复杂的文件输出,而是直接使用readfile

代码语言:javascript
复制
// 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;

看看这能不能用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6123243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档