关于jsp中<input type="file">获取路径问文件名,获取完全路径问题

来源:互联网 发布:soa面向服务架构 java 编辑:程序博客网 时间:2024/06/08 13:58

原来上传文件用js获取文件路径只需var obj=document.getElementByid(id);var path=obj.value;即可。但是升级浏览器后,获取的路径是文件名字。

网上查了一下,看到一个方法比较不错,适用于各种浏览器,返回图片绝对路径

obj就是上文提到的obj

function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}