2007-01-22

判斷上傳檔案size

<html> 
<head> 
<meta http-equiv="Content-Language" content="zh-tw"> 
<meta http-equiv="Content-Type" content="text/html; charset=big5"> 
<title>上傳</title> 
</head> 
<script language="JavaScript"> 
<!– 
function checkFile(sizeLimit) { 
var img = new Image(); 
document.MM_returnValue = false; 
img.sizeLimit = sizeLimit; 
img.src = ‘file:///’ + document.frmMain.File1.value; 
img.onload = showImageDimensions; 
}
function showImageDimensions() {
if (this.fileSize > this.sizeLimit) {
alert(‘您所選擇的檔案大小為 ‘+ (this.fileSize/1000) +’ kb,\n超過了上傳上限 ‘ + (this.sizeLimit/1000) + ‘ kb!\n不允許您上傳喔!’);
return;
}
document.MM_returnValue = true;
}
//–>
</script>
</head>
<body oncontextmenu="window.event.returnValue=false">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<form ACTION="upload.asp" METHOD="POST" name="frmMain" enctype="multipart/form-data" onSubmit="checkFile(100000);return document.MM_returnValue;">
<div align="center">
圖片: <input type="file" name="File1" size="20">
<input type="submit" name="btn1" value="確定上傳">
</div>
</form>
</td>
</tr>
</table>
</body>
</html>

沒有留言:

張貼留言