<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?
Try using gbk encoding when saving the file name, then read the file name and convert it to utf8