php 下载文件
// 文件下载 private function download ($filename, $showname='',$content='',$expire=180) { if(file_exists($filename)){ $length = filesize($filename); }elseif(is_file(UPLOAD_PATH.$filename)){ $filename = UPLOAD_PATH.$filename; $length = filesize($filename); }elseif($content != ''){ $length = strlen($content); }else { throw_exception($filename.L('下载文件不存在!')); } if(empty($showname)){ $showname = $filename; } $showname = basename($showname); if(empty($filename)){ $type = mime_content_type($filename); }else{ $type = "application/octet-stream"; } //发送Http Header信息 开始下载 header("content-type:text/html; charset=utf-8"); header("Pragma: public"); header("Cache-control: max-age=".$expire); //header('Cache-Control: no-store, no-cache, must-revalidate'); header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT"); //下面一行就是改动的地方,即用iconv("UTF-8","GB2312//TRANSLIT",$showname)系统函数转换编码为gb2312 header("Content-Disposition: attachment; filename=". iconv("UTF-8","GB2312",$showname)); header("Content-Length: ".$length); header("Content-type: ".$type); header('Content-Encoding: none'); header("Content-Transfer-Encoding: binary" ); if($content == '' ) { readfile($filename); } else { echo($content); } exit(); }