php move_uploaded_file 上传的文件移动带中文文件名的的问题

错误如下:

Warning: move_uploaded_file(xxx.gif) [function.move-uploaded-file]: faild to open stream : Invalid atgument in xxx line 25

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php80.tmp' to xxx' in xxx line 25

并且文件移动失败!

原因:

php字符编码和windows不同的问题,简体中文版的windows对文件名的命名一般使用gbk或gb2312编码。而php中的非ASCII字符串变量的值大多使用utf8编码(当然,这个默认值可以修改。。),所以在处理带中文的路径的时候需要转码

处理方法

例:

move_uploaded_file($_FILES["file"]["tmp_name"],"./upload/" . $_FILES["file"]["name"]);
改成
move_uploaded_file($_FILES["file"]["tmp_name"],"./upload/" . mb_convert_encoding($_FILES["file"]["name"],"gbk", "utf-8"));