if(filefujianChange($("#fileid").get(0))){
var formData = new FormData($('#auForm')[0]);
var that =$(this);
$.ajax({
type: 'post',
url: xtpath+"/backstage/biz/oil/oillistprice/importExcle",
data: formData,
cache: false,
processData: false,
contentType: false,
}).success(function (data) {
that.dialog("close");
var msg = JSON.parse(data);
XT.Model.info(msg.resMsg,function(){getbaseList();});
}).error(function () {
alert("上传失败");
});
}
简单判断上传格式以及大小
function filefujianChange(target) {
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>2000){
alert("附件不能大于2M");
target.value="";
return
}
var name=target.value;
var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
if(fileName !="jpg" && fileName !="jpeg" && fileName !="pdf"
&& fileName !="png" && fileName !="dwg" && fileName !="gif" ){
alert("请选择图片格式文件上传(jpg,png,gif,dwg,pdf,gif等)!");
target.value="";
return
}
}