js检测文件类型及大小
function CheckFileType()
{
var objButton=document.getElementById("buttonsubmit");
var objFileUpload=document.getElementById('Upload');
var objMSG=document.getElementById('msg');
var FileName=new String(objFileUpload.value);
var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));
var image=new Image();
image.dynsrc=objFileUpload.value;
var FileSize=Math.round(image.fileSize/1024*100)/100;
if(FileSize>100)
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>File too large.</div>";
return;
}
if(extension.toLowerCase()=="xls"||extension.toLowerCase()=="csv")
{
objButton.disabled=false;
objMSG.innerHTML="";
}
else
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>FileType error.</div>";
}
}
______________________________________________________________
function CheckFileType()
{
var objButton=document.getElementById("buttonsubmit");
var objFileUpload=document.getElementById('Upload');
var FileSize=Math.round(getFileSize(objFileUpload.value)/1024*100)/100;//取得图片文件的大小
var objMSG=document.getElementById('msg');
var FileName=new String(objFileUpload.value);
var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));
if(FileSize>100)
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>File too large.</div>";
return;
}
if(extension.toLowerCase()=="xls"||extension.toLowerCase()=="csv")
{
objButton.disabled=false;
objMSG.innerHTML="";
}
else
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>FileType error.</div>";
}
}
function getFileSize(filePath)
{
var image=new Image();
image.dynsrc=filePath;
return image.fileSize; //不是图片文件也能检测其大小
}
{
var objButton=document.getElementById("buttonsubmit");
var objFileUpload=document.getElementById('Upload');
var objMSG=document.getElementById('msg');
var FileName=new String(objFileUpload.value);
var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));
var image=new Image();
image.dynsrc=objFileUpload.value;
var FileSize=Math.round(image.fileSize/1024*100)/100;
if(FileSize>100)
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>File too large.</div>";
return;
}
if(extension.toLowerCase()=="xls"||extension.toLowerCase()=="csv")
{
objButton.disabled=false;
objMSG.innerHTML="";
}
else
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>FileType error.</div>";
}
}
______________________________________________________________
function CheckFileType()
{
var objButton=document.getElementById("buttonsubmit");
var objFileUpload=document.getElementById('Upload');
var FileSize=Math.round(getFileSize(objFileUpload.value)/1024*100)/100;//取得图片文件的大小
var objMSG=document.getElementById('msg');
var FileName=new String(objFileUpload.value);
var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));
if(FileSize>100)
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>File too large.</div>";
return;
}
if(extension.toLowerCase()=="xls"||extension.toLowerCase()=="csv")
{
objButton.disabled=false;
objMSG.innerHTML="";
}
else
{
objButton.disabled=true;
objMSG.innerHTML="<div style='border:#CCCCCC dotted 1px; background-color:#FFFFCC; padding:5px; margin:10px auto; color:#FF0000;'>FileType error.</div>";
}
}
function getFileSize(filePath)
{
var image=new Image();
image.dynsrc=filePath;
return image.fileSize; //不是图片文件也能检测其大小
}