//检测文件大小和类型
function fileChange(target){
//检测上传文件的类型
if(!(/(?:jpg|gif|png|jpeg)$/i.test(target.value))) {
alert("只允许上传jpg|gif|png|jpeg格式的图片");
if(window.ActiveXObject) {
target.select();
document.selection.clear();
} else if(window.opera) {
target.type="text";target.type="file";
} else target.value="";
return;
} else {
return;
}
//检测上传文件的大小
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
var fileSize = 0;
if (isIE && !target.files){
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
} else {
fileSize = target.files[0].size;
}
var size = fileSize / 1024;
if(size>(5120)){
alert("文件大小不能超过5M");
if(window.ActiveXObject) {
target.select();
document.selection.clear();
} else if(window.opera) {
target.type="text";target.type="file";
} else {
target.value="";
}
return;
}else{
return;
}
}
function fileChange(target){
//检测上传文件的类型
if(!(/(?:jpg|gif|png|jpeg)$/i.test(target.value))) {
alert("只允许上传jpg|gif|png|jpeg格式的图片");
if(window.ActiveXObject) {
target.select();
document.selection.clear();
} else if(window.opera) {
target.type="text";target.type="file";
} else target.value="";
return;
} else {
return;
}
//检测上传文件的大小
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
var fileSize = 0;
if (isIE && !target.files){
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
} else {
fileSize = target.files[0].size;
}
var size = fileSize / 1024;
if(size>(5120)){
alert("文件大小不能超过5M");
if(window.ActiveXObject) {
target.select();
document.selection.clear();
} else if(window.opera) {
target.type="text";target.type="file";
} else {
target.value="";
}
return;
}else{
return;
}
}