• 比较恶心的360老年版浏览器 文件导出下载


    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 = "序号	卡号	卡密码	生成日期	有效期(天)	充值期限	金额
    ";
                fwrite($fp_write,$row);
                $i=1;
                foreach ($data as $key => $value) { 
                      $row = "$i	{$value['cardnum']}	{$value['cardpwd']}	{$value['createtime']}	{$value['validityday']}	".date('Y-m-d',$value['expirydate'])."	{$value['money']}
    "; 
                      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(); }


     

  • 相关阅读:
    App性能测试工具-PerfDog
    痛并快乐着
    SQLyog连接MySQL的前前后后
    组合模式
    Java并发编程:线程池的使用
    高效能人事的七个习惯
    Spring中Bean的生命周期及其扩展点
    (转)第一次有人把“分布式事务”讲的这么简单明了
    分布式事物
    mybatis学习笔记(2)基本原理
  • 原文地址:https://www.cnblogs.com/timelesszhuang/p/3765679.html
Copyright © 2020-2023  润新知