php ie9自动下载

时间:2011-05-25 10:47:56

标签: php automation download internet-explorer-9

嗨,大家好我想让人们去一个页面时出现一个自动下载框。 我已经在所有的浏览器上工作了,现在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;

有什么想法吗?

1 个答案:

答案 0 :(得分: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;

看看是否有效。

相关问题