php代码生成txt文件并下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
     header( "Content-Type: application/octet-stream" );
       
     $quan = $_GET [ 'quan' ];
     $ua  $_SERVER [ "HTTP_USER_AGENT" ];
     $filename  "100yuan.txt" ;
     $encoded_filename  = urlencode( $filename );
     $encoded_filename  str_replace ( "+" "%20" $encoded_filename );
       
     if  (preg_match( "/MSIE/" $_SERVER [ 'HTTP_USER_AGENT' ]) ) {
         header( 'Content-Disposition:  attachment; filename="'  $encoded_filename  '"' );
     elseif  (preg_match( "/Firefox/" $_SERVER [ 'HTTP_USER_AGENT' ])) {
        // header('Content-Disposition: attachment; filename*="utf8' .  $filename . '"');
         header( 'Content-Disposition: attachment; filename*="'  .   $filename  '"' );
     else  {
         header( 'Content-Disposition: attachment; filename="'  .   $filename  '"' );
     }
       
     echo  '您已领取100元现金券。现金券编码是:' . $quan ;
?>