以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]上传图片修改名称 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=120575) |
-- 作者:OKK -- 发布时间:2018/6/19 19:44:00 -- [求助]上传图片修改名称 http://www.foxtable.com/mobilehelp/scr/0251.htm If filesys.FileExists(fl) Dim idx As Integer = fl.LastIndexOf(".") Dim ext As String = fl.SubString(idx) Select Case ext Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar" e.WriteFile(fl) Return \'这里必须返回 End Select End If Select Case e.Path Case "upload.htm" Dim wb As New weui wb.AddForm("","form1","receive.htm") With wb.AddInputGroup("form1","ipg1","文件上传") With .AddUploader("up128","照片",True) .AllowDelete = True \'允许删除 .Incremental = True \'允许重复选择文件或连续拍照 .ScaleWidth = 400 \'自动压缩图片宽度为400个像素,高度等比例压缩 End With End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "确定", "button").Attribute= "" \'调用js函数上传 End With wb.AddToast("","tst1", "正在上传",1) wb.AddToast("","tst2", "上传成功",0) wb.AddToast("","tst3", "上传失败",0).Icon= "warn" wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件 e.WriteString(wb.Build) \'生成网页 Case "receive.htm" For Each key As String In e.Files.Keys For Each fln As String In e.Files(key) e.SaveFile(key,fln,"d:\\web\\uploadfiles\\" & fln) \'保存接收到的文件 Next Next e.WriteString("OK") End Select 以上代码可以上传多张图片,但上传的时候都是使用原来的图片名称的 请问有没有办法修改图片名称,比如同时上传10张图片,把名称更改为"我的图片" & 1 to 10 & ".jpg" dim i as integer = 1 to 10 dim aa as string = "我的图片" & i & ".jpg" e.SaveFile(key,fln,"d:\\web\\uploadfiles\\" & aa) \'保存接收到的文件
|
-- 作者:有点蓝 -- 发布时间:2018/6/19 20:23:00 -- 不建议使用序号,因为多人上传的话 ,就会重复了,一般用时间(精确到毫秒)+序号 Case "receive.htm" Dim i As Integer = 1 For Each key As String In e.Files.Keys For Each fln As String In e.Files(key) e.SaveFile(key,fln,"d:\\web\\uploadfiles\\我的图片" & Format(Date.Now,"_yyMMddHHmmssfff_") & i & ".jpg") \'保存接收到的文件 i = i+1 Next i = i+1 Next e.WriteString("OK") |
-- 作者:OKK -- 发布时间:2018/6/19 21:11:00 -- 明白,谢谢 |