Home >php教程 >php手册 >php utf8编码上传中文文件名出现乱码

php utf8编码上传中文文件名出现乱码

WBOY
WBOYOriginal
2016-06-13 09:56:49909browse

下面我来总结一下php utf8编码上传中文文件名出现乱码解决办法,有碰这类问题的朋友可参考参考。

 代码如下 复制代码

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:文件路径

*****/

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