我做了一个会员管理系统,在实现照片上传的代码如下:
$fileinfo="";
if(isset($_POST['btnUpload'])){
$uploaddir="photos/";
if(!file_exists($uploaddir)) mkdir($uploaddir);
$path=pathinfo($_FILES["filePhoto"]["name"]);
$ext=$path["extension"];
$uploadfile=$uploaddir.$_SESSION["MM_Username"].".".$ext;

if(move_uploaded_file($_FILES["filePhoto"]["tmp_name"],$uploadfile)){
$fileinfo="<br>文件名:".$_FILES["filePhoto"]["name"]."<br>";
$fileinfo.="文件类型:".$_FILES["filePhoto"]["type"]."<br>";
$fileinfo.="文件大小:".$_FILES["filePhoto"]["size"]."字节<br>";
$fileinfo.="文件上传成功!<br>";
$insertSql=sprintf("update members set photo='%s' where username='%s'",$uploadfile,$_SESSION['MM_Username']);
$insertRs=mysql_query($insertSql) or die(mysql_error());
if($insertRs) $fileinfo.="照片信息已经成功保存到数据库中。<br>";
else{
$fileinfo="<P>文件上传失败!";
}
}

}
其中$_SESSION["MM_Username"]为登录会员名,当会员名字为数字或英文的时候上传很顺利,但如果会员名字为汉字就会出现问题:Warning: move_uploaded_file(photos/张博强.jpg) [function.move-uploaded-file]: failed to open stream: Invalid argument in E:\program files\apache\htdocs\huiyuanguanli\upload.php on line 56Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php19.tmp' to 'photos/张博强.jpg' in E:\program files\apache\htdocs\huiyuanguanli\upload.php on line 56
请问高手我该如何解决这个问题呢?是不是字符编码的问题?

解决方案 »

  1.   

    iconv('GBK', 'UTF-8', '中文文件名')
    windows系统,需要将编码转换为gbk
    linux需要将编码转换为utf-8
      

  2.   

    尽量不要用中文名   比如含中文的话,提取特征值,转换成字母+数字如果非要用,将路径转码UTF-8  GBK  试试
      

  3.   

    可是我现在根本不知道$_SESSION["MM_Username"]的中文用户名用的是什么编码?它为什么不能被move_uploaded_file()函数所成功转移?若文件名带中文,是可以的,但惟独就是以$_SESSION["MM_Username"]传过来的中文用户名转为文件名之后无法上传!