火狐IE下获取完整文件路径名的方法

来源:互联网 发布:pps for mac官方下载 编辑:程序博客网 时间:2024/05/16 19:09

抄:

 

以下为引用的内容:
<input name="upfile1" type="file" id="upfile1" onchange="SeePicNew2('uploadfield1',this);" />
<div class="divpre" id='uploadfield1'></div>


function SeePicNew2(imgdid,f) {
if(f.value=='') return ;
var newPreview = document.getElementById(imgdid);

// 这段代码是关键,如果是FF,则f.fles为真
if (f.files) {
var filepath = f.files.item(0).getAsDataURL();
} else {
var filepath = 'file:///'+f.value.replace(////g,"/").replace(//:/,"|");
}

var image = new Image(); var ImgD = new Image();
ImgD.src = filepath;
image.src = ImgD.src; FitWidth = 150; FitHeight = 100;
if(image.width>0 && image.height>0)
{
if(image.width/image.height>= FitWidth/FitHeight)
{
if(image.width>FitWidth)
{
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>FitHeight)
{
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}

newPreview.style.width = ImgD.width+"px";
newPreview.style.height = ImgD.height+"px";

if(window.navigator.userAgent.indexOf("MSIE") < 1)
{
newPreview.style.background = "url('"+ImgD.src+"') no-repeat";
}
else
{
newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ImgD.src+"',sizingMethod='scale')";
}

ImgD = image = null;
//newPreview.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = f.value;
}
原创粉丝点击