//单文件上传:定制类方案一
function btnok_custom_fileupload(hfdelimageid, hfiswaterid, hfmoduleid) {
//开始提交
$("#form1").ajaxsubmit({//模板页中,form生成id都叫“aspnetform”
beforesubmit: function (formdata, jqform, options) {
//显示loading图片
//隐藏上传按钮
$(".files").hide();
//显示loading图片
$(".uploading").show();
},
success: function (data, textstatus) {
if (data.result == 1) {
var valj = json.parse(data.returnval);
var imginli = valj[0].split('$');
var curimgpath = imginli[0];
var upfilename = imginli[1];
$("#" + hfdelimageid).val(curimgpath);
$("#txtimgpath").val(curimgpath);
var va = curimgpath.tostring();
va = va.substr(va.length - 15, 15);
$("#upimgname").html("" + va + "");
} else {
alert(data.returnval);
}
$(".files").show();
$(".uploading").hide();
},
error: function (data, status, e) {
alert("上传失败,错误信息:" + e);
$(".files").show();
$(".uploading").hide();
return false;
},
type: "post",
datatype: "json",
data: { uploadid: "fileupload", module: $("#" + hfmoduleid).val(), delfile: $("#" + hfdelimageid).val(), iswater: $("#" + hfiswaterid).val() },
url: "/controls/tools/multipleupload.ashx?type=up¶m=" + new date().gettime(),
timeout: 300000
});
}
//单文件上传:通用类方案二
function btnok_fileupload(formid, uploaditemid, uploadid, hfdelimageid) {
var modulename = $("#" + uploaditemid).attr("modulename");
var iswater = $("#" + uploaditemid).attr("iswater");
var $filectl = $("#" + uploaditemid).find(".filectl")[0];
var $uploading = $("#" + uploaditemid).find(".uploading")[0];
var $txtpath = $("#" + uploaditemid + ">.txtpath")[0];
var isreplacefile = $("#" + uploaditemid).attr("isreplacefile");
var isresource = $("#" + uploaditemid).attr("isresource");
var limitsize = $("#" + uploaditemid).attr("limitsize");
//开始提交
$("#" + formid).ajaxsubmit({//模板页中,form生成id都叫“aspnetform”
beforesubmit: function (formdata, jqform, options) {
//显示loading图片
//隐藏上传按钮
$($filectl).hide();
//显示loading图片
$($uploading).show();
},
success: function (data, textstatus) {
if (data.result == 1) {
var valj = json.parse(data.returnval);
var imginli = valj[0].split('$');
var curimgpath = imginli[0];
var upfilename = imginli[1];
$("#" + hfdelimageid).val(curimgpath);
if (typeof afteruploadimg == "function") {
afteruploadimg();
}
$($txtpath).val(curimgpath);
var va = curimgpath.tostring();
va = va.substr(va.length - 15, 15);
$("#upimgname").html("" + va + "");
} else {
alert(data.returnval);
}
$($filectl).show();
$($uploading).hide();
},
error: function (data, status, e) {
alert("上传失败,错误信息:" + e);
$($filectl).show();
$($uploading).hide();
return false;
},
type: "post",
datatype: "json",
data: { uploadid: uploadid, module: modulename, delfile: $("#" + hfdelimageid).val(), iswater: iswater, isreplacefile: isreplacefile, isresource: isresource, limitsize: limitsize },
url: "/controls/tools/multipleupload.ashx?type=up¶m=" + new date().gettime(),
timeout: 300000
});
}
//单文件上传:通用方案三:图片上传展示,如:身份证上传,一寸证件照上传等
function showimgupload(formid, uploaditemid, uploadid, showimgid) {
var modulename = $("#" + uploaditemid).attr("modulename");
var iswater = $("#" + uploaditemid).attr("iswater");
var $filectl = $("#" + uploaditemid).find(".filectl")[0];
var $uploading = $("#" + uploaditemid).find(".uploading")[0];
var $txtpath = $("#" + uploaditemid + ">.txtpath")[0];
var isreplacefile = $("#" + uploaditemid).attr("isreplacefile");
var isresource = $("#" + uploaditemid).attr("isresource");
var limitsize = $("#" + uploaditemid).attr("limitsize");
//开始提交
$("#" + formid).ajaxsubmit({//模板页中,form生成id都叫“aspnetform”
beforesubmit: function (formdata, jqform, options) {
//显示loading图片
$($uploading).show();
},
success: function (data, textstatus) {
if (data.result == 1) {
var valj = json.parse(data.returnval);
var imginli = valj[0].split('$');
var curimgpath = imginli[0];
var upfilename = imginli[1];
console.log(curimgpath);
$("#" + showimgid).attr('src', curimgpath);
if (typeof afteruploadimg == "function") {
afteruploadimg();
}
$($txtpath).val(curimgpath);
var va = curimgpath.tostring();
va = va.substr(va.length - 15, 15);
$("#upimgname").html("" + va + "");
} else {
alert(data.returnval);
}
$($uploading).hide();
},
error: function (data, status, e) {
alert("上传失败,错误信息:" + e);
$($filectl).show();
$($uploading).hide();
return false;
},
type: "post",
datatype: "json",
data: { uploadid: uploadid, module: modulename, delfile: "", iswater: iswater, isreplacefile: isreplacefile, isresource: isresource, limitsize: limitsize },
url: "/controls/tools/multipleupload.ashx?type=up¶m=" + new date().gettime(),
timeout: 300000
});
}
//多文件上传:通用方案一 回调“toiniupimgs(json);”获取返回的图片json
function imgsupload(formid, uploaditemid, uploadid) {
var modulename = $("#" + uploaditemid).attr("modulename");
var iswater = $("#" + uploaditemid).attr("iswater");
var $filectl = $("#" + uploaditemid).find(".filectl")[0];
var $uploading = $("#" + uploaditemid).find(".uploading")[0];
var $txtpath = $("#" + uploaditemid + ">.txtpath")[0];
var isreplacefile = "0";
var isresource = $("#" + uploaditemid).attr("isresource");
var limitsize = $("#" + uploaditemid).attr("limitsize");
//开始提交
$("#" + formid).ajaxsubmit({//模板页中,form生成id都叫“aspnetform”
beforesubmit: function (formdata, jqform, options) {
//显示loading图片
$($uploading).show();
},
success: function (data, textstatus) {
if (data.result == 1) {
var valj = json.parse(data.returnval);
toiniupimgs(valj);
} else {
alert(data.returnval);
}
$($uploading).hide();
},
error: function (data, status, e) {
alert("上传失败,错误信息:" + e);
$($filectl).show();
$($uploading).hide();
return false;
},
type: "post",
datatype: "json",
data: { uploadid: uploadid, module: modulename, delfile: "", iswater: iswater, isreplacefile: isreplacefile, isresource: isresource, limitsize: limitsize },
url: "/controls/tools/multipleupload.ashx?type=up¶m=" + new date().gettime(),
timeout: 300000
});
}
//多文件逐个单传上传方案
function filesupload(formid, uploaditemid, uploadid, hfdelimageid) {
var modulename = $("#" + uploaditemid).attr("modulename");
var iswater = $("#" + uploaditemid).attr("iswater");
var $filectl = $("#" + uploaditemid).find(".filectl")[0];
var $uploading = $("#" + uploaditemid).find(".uploading")[0];
var isreplacefile = "0";
var isresource = $("#" + uploaditemid).attr("isresource");
var limitsize = $("#" + uploaditemid).attr("limitsize");
//开始提交
$("#" + formid).ajaxsubmit({//模板页中,form生成id都叫“aspnetform”
beforesubmit: function (formdata, jqform, options) {
//显示loading图片
//隐藏上传按钮
$($filectl).hide();
//显示loading图片
$($uploading).show();
},
success: function (data, textstatus) {
if (data.result == 1) {
if (typeof afteruploadimg == "function") {
afteruploadimg();
}
var valj = json.parse(data.returnval);
var imginli = valj[0].split('$');
var curimgpath = imginli[0];
var upfilename = imginli[1];
toiniimgsafterup(curimgpath);
} else {
alert(data.returnval);
}
$($filectl).show();
$($uploading).hide();
},
error: function (data, status, e) {
alert("上传失败,错误信息:" + e);
$($filectl).show();
$($uploading).hide();
return false;
},
type: "post",
datatype: "json",
data: { uploadid: uploadid, module: modulename, delfile: $("#" + hfdelimageid).val(), iswater: iswater, isreplacefile: isreplacefile, isresource: isresource, limitsize: limitsize },
url: "/controls/tools/multipleupload.ashx?type=up¶m=" + new date().gettime(),
timeout: 300000
});
}
//从页面直接删除
function upfile_delete_page(modulename, hfdelimageid) {
$.ajax({
type: "post", //此时,所有data数据,都默认加到url里
datatype: "json",
data: { modulename: modulename, filepath: $("#" + hfdelimageid).val() },
url: "/controls/tools/multipleupload.ashx?type=delete¶m=" + new date().gettime(),
success: function (d) {
var result = d.result;
switch (result) {
case '-1':
alert(d.returnval);
break;
case '1':
$("#upimgname").html('');
$("#" + hfdelimageid).val('');
break;
default:
$("#upimgname").html('');
$("#" + hfdelimageid).val('');
break;
}
},
error: function (xmlhttprequest, textstatus, errorthrown) {
if (errorthrown) { alert(textstatus + ":" + errorthrown); }
}
});
}
function upfile_delete(modulename, filepath) {
$.ajax({
type: "post", //此时,所有data数据,都默认加到url里
datatype: "json",
data: { modulename: modulename, filepath: filepath },
url: "/controls/tools/multipleupload.ashx?type=delete¶m=" + new date().gettime(),
success: function (d) {
var result = d.result;
switch (result) {
case '-1':
alert(d.returnval);
break;
case '1':
$("#upimgname").html('');
break;
default:
$("#upimgname").html('');
break;
}
},
error: function (xmlhttprequest, textstatus, errorthrown) {
if (errorthrown) { alert(textstatus + ":" + errorthrown); }
}
});
}