发表于: 2007/06/01 02:20pm
|
问题已经解决了,回贴一下,与大家共享;如果大家有更好的解决办法,请尽快回复噢
javascript这样来写:
//文件大小验证函数,超过规定的上限,就不让上传,给用户提示
//如果文件超过5M,就不让上传
function fileSizeValidate()
{
var filestr = document.all.UploadFile.value;
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(filestr);
if(f.size>5*1024*1024){
alert("The size of .dbf is more than 5M");
return false;
}
return true;
}
页面里是这样的:
<TR valign=middle align=center height=40 width="100%">
<form name=Uploadform method=post encType="multipart/form-data">
<TD align=left width="60%">
<INPUT class=input id=UploadFile type=file size=30 name=UploadFile>
</TD>
</form>
<TD align=center width="20%">
<INPUT class=Btn1_w60 onclick="fileSizeValidate()" type=button value=upload>
</TD>
</TR>
|
顶部 |
zhangxin |
发表于: 2007/06/01 02:35pm
|
其实之前我也对文件类型做了判断,在此一并与大家共享一下:
function pstn2ngnMigration(){
if (dbfFileNameValidate()){
if(fileSizeValidate()){
if(confirm("do you want to execute migration ?")){
lockSystem('please waiting...',false)
setTimeout("dbfFileMigration()",3000);
}
}
}
}
//判断是否是.DBF文件,是返回true
function dbfFileNameValidate()
{
var filestr = document.all.UploadFile.value;
if(filestr==""){
alert("Please select a migration file!");
document.all.UploadFile.focus();
return false;
}else if(filestr.toLowerCase().lastIndexOf(".dbf")==-1){
alert("Please select a file with DBF extension !");
document.all.UploadFile.focus();
return false;
}
return true;
}
//条件成立,提交
function dbfFileMigration()
{
document.Uploadform.action="MigrationSendOrder.jsp";
document.Uploadform.submit();
unlockSystem();
}
//上传文件大小限制
function fileSizeValidate()
{
var filestr = document.all.UploadFile.value;
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(filestr);
if(f.size>5*1024*1024){
alert("The size of .dbf is more than 5M");
return false;
}
return true;
}
页面代码如下:
<TR valign=middle align=center height=40 width="100%">
<form name=Uploadform method=post encType="multipart/form-data">
<TD align=left width="60%">
<INPUT class=input id=UploadFile type=file size=30 name=UploadFile>
</TD>
</form>
<TD align=center width="20%">
<INPUT class=Btn1_w60 onclick="pstn2ngnMigration()" type=button value=upload>
</TD>
</TR> |
=====================================================
包括文件类型的判断:
function checkSize(files)
{
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(files);
var mySize = f.size/1024;
alert(mySize+" K ");
}
<!-- Begin
extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (!allowSubmit)
alert("对不起,只能上传以下格式的文件: "
+ (extArray.join(" ")) + "\n请重新选择符合条件的文件"
+ "再上传.");
}
// End -->
posted on 2008-12-11 23:44
CopyHoo 阅读(568)
评论(0) 编辑 收藏 所属分类:
JavaScript