2011-05-25 190 views
0

嗨,大家好,我試圖讓人們去一個頁面時出現一個自動下載框。 我已經有了所有的瀏覽器這方面的工作,現在IE9已經來到沿,雖然它在下載結束它說:「這下載中斷」php 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; 

任何想法?你正在做

+2

爲什麼你要發送兩個'Content-Description:File Transfer'頭文件? – zacharydanger 2011-05-25 10:58:05

+1

你有2個內容說明:'並且不需要'\ n's'的標題 – 2011-05-25 11:00:07

+0

2 Content-Description:文件傳輸是它!,我不知道如何給你道具 - 我點擊了箭頭旁邊的評論,但無論如何,歡呼,讓我們難倒了大半天早上! – 2011-05-25 12:06:23

回答

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; 

看看是否能工程。

+0

+1 ...並且丟失不真正做任何事情的頭文件()語句(即至少一半) – symcbean 2011-05-25 12:35:42