PHP about downloading Chinese files

不言
Release: 2023-03-22 20:50:01
Original
1402 people have browsed it

本篇文章和大家分享了php 关于下载中文文件实现 ,有需要的朋友可以参考一下

在php的下载上遇到了下载中文文件乱码的问题
记录一下代码:
test.php:

$filename  = '中文.doc';
$filename = urlencode($filename);
echo $filename;
echo "<a href='download.php?filename=".$filename."'>下载</a>";
Copy after login

?>

download.php:

$filename = $_REQUEST['filename'];
<strong>$filename = iconv('utf-8', 'gb2312', $filename);</strong> // 这是最关键的一句,我原以为urlencode以后就不用转格式了。
header("Content-Type: application/octet-stream;");  
header('Content-Disposition:attachment;filename=' .$filename);    
readfile($filename);
Copy after login

好吧 就这样 睡觉了。。ZZZZ



The above is the detailed content of PHP about downloading Chinese files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template