我把上传图片页面代码、处理图片页面代码和js贴出来了。楼上代码应该放哪?(现有的图片审核是在js里面处理的)
图片上传页代码:
Dim e As RequestEventArgs = args(0) '注册第7页,上传照片
Dim wb As New weui
If e.PostValues.Count = 0 Then
wb.AddTopTips("","toptip1","") '用于显示动态错误提示
wb.AddForm("","form1","valid_images.htm")
With wb.AddInputGroup("form1","ipg1","展示照(选择1张靓照即可)") '文件上传(1个)
With.AddUploader("up1","",False)
.AllowDelete = True '允许用户删除图片
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
End With
With wb.AddInputGroup("form1","ipg22","生活照(选择3张以上靓照)") '带图片浏览的文件上传(最少4个)
With.AddUploader("up4","",True) 'True表示允许一次上传多个文件
.AllowDelete = True '允许删除
.Incremental = True '允许 重复选择文件或连续拍照
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "提交", "button").Attri-bute= "on-click='validit_images()'" '调用js函数上传
End With
wb.AddToast("","tst1", "正在上传",1)
wb.AddToast("","tst2", "上传成功",0)
wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
wb.AppendHTML("<script src='./lib/ajax-form_images.js'></script>") '引入脚本文件
e.WriteString(wb.Build) '生成网页
End If
图片处理页面:
Dim e As RequestEventArgs = args(0) '验证页面(照片)
Dim wb As New weui
Dim NewName As String '应该是照片的新名字
Dim drbianh As String = e.Cookies("drbianhao") '为cookie传递数据
Dim dr As DataRow = DataTables("会员资料").sql-Find("会员编号 = '" & drbianh & "'")
If dr IsNot Nothing Then '测试代码:msgbox(e.PostValues("isr"))
For Each key As String In e.Files.Keys
If key = "up1" Then
For Each fln As String In e.Files(key)
'msgbox(0)
Dim ext As String = fln.Split(".")(1)
NewName = Format(Date.Now, "yyyyMMddHHmmss") & Rand.Next(10000,99999) & "." & ext
e.SaveFile(key, fln, "e:\web\zsz\d\" & Format(Date.Today, "yyyyMM") & "\" & NewName)
dr("展示照") &= iif(dr.IsNull("展示照"), "", vbcrlf) & Format(Date.Today, "yyyyMM") & "\" & NewName
Next
End If
Next
For Each key1 As String In e.Files.Keys
If key1 = "up4" Then
For Each fln1 As String In e.Files(key1)
Dim ext1 As String = fln1.Split(".")(1)
NewName = Format(Date.Now, "yyyyMMddHHmmss") & Rand.Next(10000,99999) & "." & ext1
e.SaveFile(key1, fln1, "e:\web\shz\d\" & Format(Date.Today, "yyyyMM") & "\" & NewName)
dr("生活照") &= iif(dr.IsNull("生活照"), "", vbcrlf) & Format(Date.Today, "yyyyMM") & "\" & NewName
Next
End If
Next
dr.save() '保存
e.WriteString("OK") '生成网页
Else
e.WriteString("没有找到会员行!请重新登录,再试!")
End If
js代码:
function validit_images(){
var v1 = docu-ment.get-ElementById("up1_thumbnails").get-ElementsByTagName("li").length;
var v2 = docu-ment.get-ElementById("up4_thumbnails").get-ElementsByTagName("li").length;
//alert(v1 + " " + v2);
var frm = docu-ment.get-ElementById("form1");
var frmdata = new FormData(frm);
if (frm.incremental) {
var fluds = frm.get-ElementsByClassName("weui_uploader_input");
for (var idx = 0; idx < fluds.length; idx++) {
var files = fluds[idx].Files;
if (files) {
for (var i = 0; i < files.length; i++) {
alert(files[i].blobFile);
var fln = files[i].blobFile
if (typeof(fln) == "undefined") {
//alert("照片格式不正确");
showTopTips("toptip1","照片格式不正确!",2000);
return false;
}
fln = fln.substring(fln.lastIndexOf(".") + 1).toLowerCase();
switch (fln) {
case "jpg":
case "jpeg":
case "png":
case "gif":
case "bmp":
break;
default:
//alert("照片格式不正确");
showTopTips("toptip1","照片格式不正确!",2000);
return false;
}
}
}
}
}
if(v1 < 1){
showTopTips("toptip1","请选择1张展示照上传!",2000);
return false;
}
if(v1 > 1){
showTopTips("toptip1","展示照只可以上传1张!",2000);
return false;
}
if(v2 < 3){
showTopTips("toptip1","请选择3张以上生活照上传!",2000);
return false;
}
if(v2 > 9){
showTopTips("toptip1","生活照最多可以上传9张!",2000);
return false;
}
show("tst1",2000);
var result = submitAjaxForm('form1','afterSubmit');
}
function afterSubmit(result){
hide("tst1");
if (result=='OK') {
show("tst2");
location="success.htm";
}
else{
show("tst3",2000);
}
}
[此贴子已经被作者于2017/9/15 16:25:44编辑过]