开发者

php ie9 automatic downloads

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");
    hea开发者_开发知识库der("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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜