-
-
$ua = $_SERVER["HTTP_USER_AGENT"]; - $filename = "Chinese file name.txt";
- $encoded_filename = urlencode($filename);
- $ encoded_filename = str_replace("+", "%20", $encoded_filename);
$ua = $_SERVER["HTTP_USER_AGENT"];
- $filename = "Chinese file name.txt";
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
- ?>
-
Copy code
The above code can support downloading Chinese file names.
2. Generate 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 . '"');
- }
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 . '"');
- }//Compatible with all kind of browser.
- ?>
-
Copy the code
3. Output content
This step is much simpler. Use echo to output directly, and "rn" is used to break the line.
The output content is the content in txt.
This function can also generate doc files. Just change the suffix to .doc. However, this method can only generate simple doc files. If there are pictures or links, you will have to find another way.
Scripting School, I wish you a happy study.
|