php上传文件后文件名乱码的解决方案

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_42249896/article/details/84583300

先看一下是怎么出现乱码的:

我的所有文件编码都保存了utf-8 了怎么还会乱码?

这是因为文件名编码的问题,我们接受的文件名是中文,是utf-8编码,我转换成gbk或gb2312才行。

$filename是接受的文件名,用iconv函数转换一下即可!

$filename = iconv('utf-8','gbk',$filename);

 

转换好后:

先查看一下自己接受过来的文件名是什么编码,在进行不同的转换……

展开阅读全文

获取上传文件的路径,及文件名乱码

07-31

[code=html]rn<%@ page language="java" contentType="text/html; charset=utf-8"rn pageEncoding="utf-8"%>rn<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>rn<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>rn<%rn String path = request.getContextPath();rn String basePath = path+"/";rn rn request.setCharacterEncoding("utf-8");rn%>rnrnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rnrn rn rnrn rnrn rnrn rn rnrn rnrn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rnrnrn rn rn rn rn rn 导入Excel:rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn 提交中...rn rn rnrn rn 确定 取消rn rnrn rn rn rn rnrnrnrnrn[/code]rn这是页面rnrnrn[code=java]rn@RequestMapping(value = "/importEcl")rn @ResponseBodyrn public Map importEcl(HttpServletRequest request) throws Exception rn Map rsmap = new HashMap();rn String flag = "success", msg = "";rn String path = new String(str("path", request).getBytes(),"utf-8") ;rn List> storeList = new ArrayList>();rn if (path.endsWith("xls")) rn storeList = readXls(path);//本地环境使用rn else if (path.endsWith("xlsx")) rn storeList = readXlsx(path);rn rn for (Map store : storeList) rn Townstreet townstreet=new Townstreet();rn townstreet.setCode(store.get("arg0"));rn townstreet.setCompany_name(store.get("arg1"));rn townstreet.setRegional_level(store.get("arg2"));rn townstreet.setSales_area(store.get("arg3"));rn townstreet.setStree_name(store.get("arg4"));rn townstreet.setPopulation(store.get("arg5"));rn townstreet.setDevel_customer(store.get("arg6"));rn rn townstreetService.insert(townstreet);rn rn File tempFile = new File(path);rn tempFile.delete();rn rn rsmap.put("state", flag);rn rsmap.put("msg", msg);rn return rsmap;rn rn[/code]rn这是后台方法,获取文件路径之后保存在input中,显示出来是乱码,我提交到后台转码还是乱码。 论坛

没有更多推荐了,返回首页