【问题标题】:php ie9 automatic downloadsphp ie9 自动下载
【发布时间】:2011-05-25 10:47:56
【问题描述】:

大家好,我正在尝试在人们访问页面时显示一个自动下载框。 我在所有浏览器上都可以使用,现在 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;

有什么想法吗?

【问题讨论】:

  • 为什么要发送两个Content-Description: File Transfer 标头?
  • 你有 2 个 Content-Description:'s 并且不需要标题上的 \n's
  • 2 内容描述:文件传输就是它!,我不知道如何给你道具 - 我点击了你评论旁边的箭头,但无论如何,这让我们大部分时间都为难早上好!
  • 再次感谢您的 cmets,我已经删除了一些标题并清理了我尝试 readfile 的代码,但这些文件非常大,似乎无法正常工作。下载更好,但我仍然收到中断的消息。事实上,即使是小文件也有问题——我想知道这是否是我的互联网连接问题。如果有任何其他想法,将不胜感激。

标签: php automation download internet-explorer-9


【解决方案1】:

我将使用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;

看看这是否有效。

【讨论】:

  • +1...并丢失实际上没有做任何事情的 header() 语句(即至少一半)
猜你喜欢
  • 1970-01-01
  • 2012-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多