-
-
- /**
- * PHP file download code, Chinese without garbled characters
- * by bbs.it-home.org
- */
- $file = "/tmp/中文名.tar.gz";
-
- $filename = basename($file);
-
- header(" Content-type: application/octet-stream");
-
- //Processing Chinese file names
- $ua = $_SERVER["HTTP_USER_AGENT"];
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+ ", "%20", $encoded_filename);
- if (preg_match("/MSIE/", $ua)) {
- header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
- } else if (preg_match("/Firefox/", $ua)) {
- header("Content-Disposition: attachment; filename*="utf8''" . $filename . '"');
- } else {
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }
-
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- header ("Content-Length: ". filesize($file));
- readfile($file);
Copy code
In addition, interested friends can study the module mod_xsendfile module in the apache server, which can be used It improves the efficiency of PHP sending files.
|