<script language="JavaScript" type="text/JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 300/200){
if(image.width>300){
ImgD.width=300;
ImgD.height=(image.height*300)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>200){
ImgD.height=200;
ImgD.width=(image.width*200)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
function changesrc(){
document.yourpic.src = document.getElementsByName("filename")[0].value;
DrawImage(yourpic);
var img = new Image();
img.src = document.yourpic.src;
alert("fileSize = "+ img.fileSize/1024 +" KB");
}
</script>
<table width="100%" border="0">
<tr>
<td>
<div align="center"><img border="1" name="yourpic" onload="javascript:DrawImage(this);">
</div>
</td>
</tr>
<form name="picForm" action="#" method="post" enctype="multipart/form-data" onsubmit="return checkPic(picForm);">
<tr>
<td>
<div align="center"><input type="file" name="filename" onchange="changesrc()"></div>
</td>
</tr>
<tr>
<td>
<div align="center"><input type="submit" value="上传照片" /></div>
</td>
</tr>
</form>
</table>