<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php if($_FILES["file"]["error"]){ echo "<script>alert('没有选择文件!');location.href='http://127.0.0.1:88/seek_system/admin/help/wenjianceshi.php'</script>"; }else{ if(($_FILES["file"]["size"]<10240000)and($_FILES['file']['type']=='application/pdf')) { //防止文件名重复 $filename="./upfile/".date('YmdHis',time()+8*60*60).'-'.$_FILES["file"]["name"]; //转码 $filename=iconv("UTF-8","gb2312",$filename); if(file_exists($filename)){ echo "该文件已存在"; }else{ //保存文件 move_uploaded_file($_FILES["file"]["tmp_name"],$filename); echo "<script>alert('上传成功!');location.href='http://127.0.0.1:88/seek_system/admin/help/wenjianceshi.php'</script>"; } }else{ echo "<script>alert('只能上传PDF文件!');location.href='http://127.0.0.1:88/seek_system/admin/help/wenjianceshi.php'</script>"; } }
The code for uploading files is as above. When I uploaded a file containing a Chinese name, I was able to successfully upload the file after transcoding, and found that the uploaded file name could also be displayed correctly in Chinese. However, the problem was that I could not open the file by clicking on the file name, and found the file name in the address bar. The Chinese part is garbled. How can I solve the problem that after transcoding, the file will have a Chinese name and the file can be opened normally?
Alone882019-04-26 14:25:15
Try using gbk encoding when saving the file name, then read the file name and convert it to utf8
生如夏花2019-04-26 09:46:20
如果我把$filename=iconv("UTF-8","gb2312",$filename);换成了$filename=iconv("gb2312","UTF-8",$filename); 发现上传成功后可以正常打开文件了,但是又出现了在浏览器上显示的文件名是乱码的。 请问结合我上面发的,这个问题该怎么解决呢?有好解决方法的请赐教。