IE6,IE8,IE9和firefox均能下载。
IE7有时能下,有时不能。
下载失败时,页面会显示$_POST的内容。但程序对$_POST没有做任何print处理。CSV下载代码如下: header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer"); //Use the switch-generated Content-Type
header("Content-Type: application/x-csv"); //Force the download
$F_header="Content-Disposition: inline; filename=".$P_DLFName.";";
header($F_header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$F_len); for ( $i=0; $i<$F_num; $i++ ){
$F_path = $PA_FName[$i];
if ($F_file = fopen($F_path, 'rb')) {
while(!feof($F_file) and (connection_status()==0)) {
print(fread($F_file, 1024*8));
flush();
}
fclose($F_file);
}
}
求解。

解决方案 »

  1.   


        $archivo="ChannelDataDetail.csv";
     
        header('Content-Type: application/download');
        header("Content-Disposition: attachment; filename='{$today}.csv'");
        header("Content-Length: " . filesize($archivo));    $fp = fopen($archivo, "r");
        fpassthru($fp);
        fclose($fp);
      

  2.   


    <?php
    require_once ("_global.inc.php");$dlfile = get_dlfile_url($_SERVER['QUERY_STRING'], 'http://www.ydtuiguang.com/', 'download/');//检查文件路径限制下载其它目录文件
    if(!exists_file($dlfile)){
        message_box('1040');
    }
    $filename = get_file_name($dlfile);
    $fileext = get_file_ext($dlfile);
    if(in_array(strtolower($fileext), array("", "js", "php", "inc", "xml", "html", "htm"))){//检测文件类型防止下载代码文件
        message_box('1040');
    }
    //调用下载
    _private_download($dlfile, $filename.'.'.$fileext);
    //以下是下PHP下载大文件函数
    function _private_download($url, $filename){
        // 获得文件大小, 防止超过2G的文件, 用sprintf来读
        $filesize = sprintf("%u", filesize($url)); 
        if (!$filesize) 
        { 
            return; 
        }        
        header("Content-type:application/octet-stream\n"); //application/octet-stream 
        header("Content-type:unknown/unknown;"); 
        header("Content-disposition: attachment; filename=\"".$filename."\""); 
        header('Content-transfer-encoding: binary');         
        if ($range = getenv('HTTP_RANGE')) // 当有偏移量的时候,采用206的断点续传头 
        { 
            $range = explode('=', $range); 
            $range = $range[1]; 
        
            header("HTTP/1.1 206 Partial Content"); 
            header("Date: " . gmdate("D, d M Y H:i:s") . " GMT"); 
            header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($url))." GMT"); 
            header("Accept-Ranges: bytes"); 
            header("Content-Length:".($filesize - $range)); 
            header("Content-Range: bytes ".$range.($filesize-1)."/".$filesize); 
            header("Connection: close"."\n\n"); 
        } 
        else 
        { 
            header("Content-Length:".$filesize."\n\n"); 
            $range = 0; 
        }
       _private_loadFile($url);               
    }function _private_loadFile($filename, $retbytes = true) {
        $buffer = '';
        $cnt =0;        
        $handle = fopen($filename, 'rb');
        if ($handle === false) {
            return false;
        }
        while (!feof($handle)) {
            $buffer = fread($handle, 1024*1024);
            echo $buffer;
            ob_flush();
            flush();
            if ($retbytes) {
            $cnt += strlen($buffer);
            }
        }
        $status = fclose($handle);
        if ($retbytes && $status) {
            return $cnt; // return num. bytes delivered like readfile() does.
        }
        return $status;

    ?>