How to solve the problem that php cannot upload Chinese files

藏色散人
Release: 2023-03-17 20:24:01
Original
3418 people have browsed it

php上传中文文件无法上传的解决办法:1、通过“iconv("GBK", "UTF-8", $content);”方法将中文字符编码转换一下;2、将文件重命名即可。

How to solve the problem that php cannot upload Chinese files

本教程操作环境:Windows10系统、PHP8.1版、DELL G3电脑

php上传中文文件无法上传问题怎么办

PHP 上传文件名中带中文的文件失败问题

问题产生的原因是:中文乱码问题

php文件为utf-8编码方式,

解决方案1:将中文字符编码转换一下。

函数原型:string iconv ( string in_charset, string out_charset, string str )

使用例子:$content = iconv("GBK", "UTF-8", $content);

代码如下:

$name=iconv("UTF-8","gb2312", $name);
move_uploaded_file($tmpname, "upload/".$name); 
$name=iconv("gb2312","UTF-8", $name);
Copy after login

解决方案2:文件重命名

//保存在服务器的名字则是时间戳,加文件后缀名
$saveName=time().$fileExtensions;
//取得服务器的目录的绝对路径。
$basepath=str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/";
//然后则保存这个上传文件
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$saveName);
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to solve the problem that php cannot upload 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