js上传文件获取客户端地址

时间:2023-03-08 20:22:01
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>get file input full path</title>
</head>
<body>
<input type="file" name="file" id="file" />
<!--<img id="img" src="" alt="预览" title="预览" />-->
<div class="preImg"></div>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script type="text/javascript">
$(function() {
var path,clip = $("img"),FileReader = window.FileReader; $("#file").change(function() {
if (FileReader) {
var reader = new FileReader(),file = this.files[];console.log(file);
reader.onload = function(e) {
//clip.attr("src", e.target.result);
var html = '<img src="'+e.target.result+'" width="300px" height="300px" />';
$('.preImg').html(html);
};
reader.readAsDataURL(file);
} else {
if(window.navigator.userAgent.indexOf("MSIE")>=){
$(this).select();$(this).blur();
var path=document.selection.createRange().text;
/*clip.removeAttr("src");
clip.attr("src",'');
document.getElementById('img').style.filter=
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');";*/
var image = new Image();
image.width = ;
image.height = ;
image.style.filter=
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');";
$('.preImg').html(image);
} else {
path = $(this).val();
if (/"\w\W"/.test(path)) {
path = path.slice(,-);
}
alert(path);
clip.attr("src",path);
alert(clip[].src);
}
}
});
});
</script>
</body>
</html>