txt文件下载

$content = '订购日志明细:'.$begin_date.'至'.$end_date;

if ($detail_list) {
foreach ($detail_list as $detail) {
$content .= '手机号:'.$detail['MSISDN'];
$content .= ' 归属地:全国';
$content .= ' 歌曲名称:'.$detail['CONTENT_NAME'];
$content .= ' 业务ID:'.$detail['CONTENT_ID'];

$biz_type = isset($bussiness_list[$detail['BIZ_TYPE']]) ? (($detail['BIZ_TYPE'] == '02' && $detail['FEE_TYPE'] == '03') ? '开通包月业务' : $bussiness_list[$detail['BIZ_TYPE']]) :'';
$content .= ' 业务类型:'.$biz_type;
$biz_type = '';

$content .= ' 计费触发时间:'.timeStrToDate($detail['TIME_STAMP']);
$content .= ' 价格(单位:分):'.timeStrToDate($detail['PRICE']);
}
}

$filename = 'logDetil.txt';
$this->downTxt($filename);
echo $content;
$content = '';

 

/**
* 下载文本文件
*/
function downTxt($filename) {
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");

Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($filename). ' bytes');

Header('Content-Disposition: attachment; filename='.$filename);
}

 

换行的话用"\r\n",必须是双引号才能解析。

posted @ 2013-04-16 10:48  幻星宇  阅读(248)  评论(0编辑  收藏  举报