Website: http://blog.sina.com.cn/s/blog_976934420101cpnz.html
Without further ado, let me post my code first;
$filename = $_FILES['file'][ 'name'];
$file = "../uploads/".$filename;
$file=iconv("UTF-8","GB2312//IGNORE", $file);
if (!move_uploaded_file ($_FILES['file']['tmp_name'],$file)){
echo "";
}
else{
$file=iconv("GB2312","UTF-8//IGNORE", $file);
echo "<script>alert('Upload successful, file path is "+.<span>$file.</span>+"!');</script>";
exit();
}
the above This is the code I used to solve the problem;
If the project is encoded in GB2312, this problem should not occur;
$file=iconv("UTF-8","GB2312//IGNORE", $ file); This is mainly used to convert the encoding of the file path; if the encoding is not converted, the upload will fail when the file path or file name contains spaces, and if there are Chinese characters, garbled characters will appear;
Be sure to add the path and The encoding of the name is converted back, because the project is UTF-8, the path and file name of GB2312 will be displayed as garbled characters;
My code:
if ($upfile['error']==UPLOAD_ERR_OK){
//Get the extension .txt .rar, etc.
// $extName=strtolower(end(explode('.',$upfile['name'])));
//Get the real name of the file including the suffix
$filename =$upfile['name'];
$filename=iconv("UTF-8","GB2312//IGNORE",$filename);
// $filename=iconv("GB2312","UTF -8",$filename);
$dest="../doc/secure/".$filename;
// $dest=iconv("UTF-8","GB2312//IGNORE", $dest ; >window.alert('Please make sure there are no spaces in the name of the
uploaded file
! ');";
}else{
$filename=iconv("GB2312","UTF-8//IGNORE",$filename);
$path="doc/secure/". $filename;
Get form parameters and save in the database $ sql = " ]','$_SESSION[userID]')"; mysql_query($sql); }
}
The above introduces the move_uploaded_file file upload failure. After uploading, the file name is garbled, including some aspects. I hope it will be helpful to friends who are interested in PHP tutorials.