Home  >  Article  >  Backend Development  >  PHP about downloading Chinese files

PHP about downloading Chinese files

不言
不言Original
2018-03-31 11:03:281401browse

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

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

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

?>

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);

好吧 就这样 睡觉了。。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!

Statement:
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