Home >Backend Development >PHP Tutorial >Chinese file name uploaded with php utf8 encoding appears garbled_PHP Tutorial

Chinese file name uploaded with php utf8 encoding appears garbled_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:56:481088browse

Now let me summarize the solution to the garbled Chinese file name uploaded in PHP UTF8 encoding. Friends who have encountered this kind of problem can refer to it.

The code is as follows
 代码如下 复制代码

if(isset($_FILES['file'])){
$upload='upload/'.$_FILES['file']['name'];

if(is_uploaded_file($_FILES['file']['tmp_name'])){

//iconv函数解决上传文件中文名乱码的问题,但是不提倡文件名是中文的,特别是unix/linux环境下 ,当你要输出的时候,又要给变回来,iconv('gb2312',UTF-8',$upload)

if(!move_uploaded_file($_FILES['file']['tmp_name'],iconv('UTF-8','gb2312',$upload))){

echo 'failed';

}else{
echo 'success';

}
}
else{
echo 'failed';

}

}
?> 

/******关于iconv函数的应用:string iconv ( string in_charset, string out_charset, string str )
* in_charset:传入的文件的格式

* out_charset:输出的文件的格式

* str:文件路径

*****/

Copy code
if(isset($_FILES['file'])){
$upload='upload/'.$_FILES['file']['name'];

if(is_uploaded_file($_FILES['file']['tmp_name'])){

if(!move_uploaded_file($_FILES['file']['tmp_name'],iconv('UTF-8','gb2312',$upload))){ echo 'failed'; }else{
echo 'success';
}
}
else{
echo 'failed';
}
}
?> /******About the application of iconv function: string iconv (string in_charset, string out_charset, string str)
* in_charset: The format of the incoming file
* out_charset: The format of the output file * str: file path *****/ http://www.bkjia.com/PHPjc/632150.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632150.htmlTechArticleLet me summarize the solutions to garbled Chinese file names uploaded with PHP utf8 encoding. Friends who have encountered this kind of problem Can be used for reference. The code is as follows Copy the code ?php if(isset($_FILES['...
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