现在的位置: 首页 > 综合 > 正文

html中上传文件得到文件的绝对路径!

2013年08月19日 ⁄ 综合 ⁄ 共 611字 ⁄ 字号 评论关闭

HTML中使用input type="file"上传文件时,代码中只能得到文件的名称,而有些特殊的需要要求我们必须得到上传文件的绝对路径,为此我们采用Javascript实现得到文件的绝对路径。

具体如下。

 

页面代码(只粘贴了关键代码):

<form name="thisform" method="post"

action="<%=request.getContextPath()%>/movieManage.do" id="thisform" enctype="multipart/form-data">

 

<input type="file" name="theFile" onchange="document.getElementById('theFilePath').value=this.value"/>  

 

<input type="hidden" id="theFilePath" name="theFilePath" value="">

 

</form>

 

注意:要有enctype="multipart/form-data"

 

Action代码:

String filePath = request.getParameter("theFilePath");

 

filePath既是上传文件的绝对路径。

 

 

浏览器中测试:

Firefox和IE中可以得到绝对路径。

 

谷歌Chrome浏览器最后得到的仍是文件名,可能是为了安全。在谷歌浏览器中的实现仍需探索。

 

抱歉!评论已关闭.