PHP Generate TXT file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.