页面上我定义了标签,用来上传图片
<s:file name="aa" id="aa" ContentEditable="false" size="45"></s:file>
提交时我要得到上传图片的大小和尺寸,我用下面的JS来做:
function checkImage(file){
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(file);
var fileSize = f.size ;
if((fileSize/1024) > 2){
alert("上传图片文件不能大于2K");
return false;
}
var imgSize={
width:0,
height:0
};
image=new Image();
image.src=file;
imgSize.width =image .width;
imgSize .height=image .height;
alert( imgSize.width);
return true;
}但这样我始终得不到图片的尺寸大小,一直提示0
<s:file name="aa" id="aa" ContentEditable="false" size="45"></s:file>
提交时我要得到上传图片的大小和尺寸,我用下面的JS来做:
function checkImage(file){
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(file);
var fileSize = f.size ;
if((fileSize/1024) > 2){
alert("上传图片文件不能大于2K");
return false;
}
var imgSize={
width:0,
height:0
};
image=new Image();
image.src=file;
imgSize.width =image .width;
imgSize .height=image .height;
alert( imgSize.width);
return true;
}但这样我始终得不到图片的尺寸大小,一直提示0
解决方案 »
- 如何判断网页是否加载完毕?
- iBATIS问题。会报错吗?
- 找不到错了?
- 不显示删除回复显示所有回复显示星级回复显示得分回复 >>>急急急啊!大虾进啊!wap页面空格效果没显示
- eclipse中创建web工程,为什么我把编译器改成 1.5后在项目名上就会出错
- 我那个网页我用request.setCharacterEncoding("GBK");之后还是出现存到数据库里还是乱码,这是怎么回事啊?
- 弱弱的问,怎么在xml把文件列表给屏蔽了呀。。。。
- 为什么我用的EL表达式不成功?
- 为什么不能正常显示汉字?
- 重分相求Struts+Castor JDO的例子
- 公用密钥与 keystore 不符
- 大量数据写入Excel文件
var flag=false;
function sImage(ImgS){
var image=new Image();
image.src=ImgS.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 173/173){
if(image.width>173){
ImgS.width=173;
ImgS.height=(image.height*173)/image.width;
}else{
ImgS.width=image.width;
ImgS.height=image.height;
}
//ImgS.alt="实际图片大小为"+image.width+"×"+image.height;
}
else{
if(image.height>173){
ImgS.height=173;
ImgS.width=(image.width*173)/image.height;
}else{
ImgS.width=image.width;
ImgS.height=image.height;
}
//ImgS.alt=image.width+"×"+image.height;
}
}
} 试试看吧
<input type="file" id="fileText">
<input type="button" value="getSize" onclick="checkFileChange(document.getElementById('fileText'));">
<script type="text/javascript">
var Sys = {};
if(navigator.userAgent.indexOf("MSIE")>0)
{
Sys.ie=true;
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)
{
Sys.firefox=true;
}
function checkFileChange(obj)
{
var filesize = 0;
if(Sys.firefox)
{
filesize = obj.files[0].fileSize;
}else if(Sys.ie)
{
var fileobject = new ActiveXObject ("Scripting.FileSystemObject");
var file = fileobject.GetFile (document.getElementById("fileText").value);
var filesize = file.Size;
}
alert(filesize);
}
</script>