Generate a TXT file and download it automatically when you access PHP.
$filename = "Filename.txt"; Header ("Content-type:application/octet-stream"); Header (' Content-disposition: Attachment Filename= "'. $filename. ‘"‘);
Output: Directly with the echo output, "\ r \ n" for line break. First step: Handle Chinese file name:
$ua $_server ["Http_user_agent"]; $filename = "Chinese filename. txt" ; $encoded _filename UrlEncode ($filename); $encoded _filename Str_replace $encoded _filename);
Step two: Generate TXT file:
1 Header("Content-type:application/octet-stream"); 2 if(Preg_match("/msie/",$_server[' Http_user_agent ']) ) { 3 Header(' Content-disposition:attachment; Filename= '.$encoded _filename. ‘"‘); 4}ElseIf(Preg_match("/firefox/",$_server[' Http_user_agent '])) { 5 Header(' content-disposition:attachment; filename*= ' UTF8 '.$filename. ‘"‘); 6}Else { 7 Header(' Content-disposition:attachment; Filename= '.$filename. ‘"‘); 8}
The third step: output: Directly with the echo output, "\ r \ n" for line break.
PHP Generate TXT file