When PHP generates a TXT file to access PHP, it generates a TXT file and automatically downloads it .? Step 1: process the Chinese File name: $ua%_server%http_user_agent%%%%$filename 文.txt; $ encoded_filenameurlencode ($ filename); $ encoded_filenamestr_replace (PHP generates the TXT file
Generate a TXT file and download it automatically when accessing PHP.
?
Step 1: process the Chinese File name:
$ Ua = $ _ SERVER ["HTTP_USER_AGENT"]; $ filename = "Chinese file name .txt"; $ encoded_filename = urlencode ($ filename); $ encoded_filename = str_replace ("+ ", "% 20", $ encoded_filename );
The above method supports downloading Chinese file names.
?
Step 2: generate a TXT file
header("Content-Type: application/octet-stream");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 . '"');} else {header('Content-Disposition: attachment; filename="' . $filename . '"');}
Supports various browsers.
?
Step 2: Output Content
The echo output is used directly, and "\ r \ n" is used for line feed.
?