function export_txt($data)
{Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
$destination_folder=‘./Public/file/‘;
//txt文件
$file_name=iconv(‘utf-8‘, ‘gbk‘, ‘账号卡信息‘).date(‘Y-m-d H-i-s‘,time()).‘.txt‘;
$destination = $destination_folder.$file_name; //新excel路径
$fp_write = fopen($destination,"w");
chmod($destination,0777);$row = "序号\t卡号\t卡密码\t生成日期\t有效期(天)\t充值期限\t金额\r\n";
fwrite($fp_write,$row);
$i=1;
foreach ($data as $key => $value) {
$row = "$i\t{$value[‘cardnum‘]}\t{$value[‘cardpwd‘]}\t{$value[‘createtime‘]}\t{$value[‘validityday‘]}\t".date(‘Y-m-d‘,$value[‘expirydate‘])."\t{$value[‘money‘]}\r\n";
fwrite($fp_write,$row);
//echo $row;
$i++;
}fclose($fp_write);
$file_sub_path="./Public/file/";
$file_path=$file_sub_path.$file_name;
$fp=fopen($file_path,"r");
$file_size=filesize($file_path);
//下载文件需要用到的头
$useragent = $_SERVER[‘HTTP_USER_AGENT‘];
// echo $useragent;
// 输出 Content-Disposition时候比较恶心的 还要区分大小写
if(strstr($useragent,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)")){$dis="Content-Disposition:attachment;filename=‘".$file_name."‘";
}else
{
$dis=‘Content-Disposition:attachment;filename="‘.$file_name.‘"‘;
}Header($dis);
Header("Accept-Length:".$file_size);
$buffer=1024;
$file_count=0;
while(!feof($fp) && $file_count<$file_size){
$file_con=fread($fp,$buffer);
$file_count+=$buffer;
echo $file_con;
}
fclose($fp);
exit();
}
比较恶心的360老年版浏览器 文件导出下载,布布扣,bubuko.com