以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  接收上传的文件的内容的困惑  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=170795)

--  作者:sunion
--  发布时间:2021/8/7 17:01:00
--  接收上传的文件的内容的困惑

上传图片的名称是怎么命名的?比如下面指南中的这个代码,上传到“员工”表格的的图片名称是依据原图片的名称命名的,也就是原来图片是abc.jpg,那么上传之后名称也是abc.jpg;

现在的问题是:(1)以后会不会再传一个图片,如果名称相同,就会把原来的覆盖掉呢?

(2)如果我要强制命名,比如:原来图片是abc.jpg,那么上传之后名称是“当天时间+abc.jpg;“     如20210807abc.jpg?


Dim wb As New weui
Select
Case e.Path
    Case "addnew.htm"
        If e.PostValues.Count = 0 Then
            wb.AddForm("","form1","addnew.htm")
            With wb.AddInputGroup("form1","ipg1","
增加员工")
                .AddInput("
姓名","姓名","Text") \'前一个"姓名"ID,后一个"姓名"是标题
                .AddInput("
年龄","年龄","number")
                .AddSelect("
学历","学历","大专|本科|硕士|博士")
                .AddUploader("up1","
照片",True) \'True表示允许上传多个文件
            End With
            With wb.AddButtonGroup("form1","btg1",True)
                .Add("btn1", "
确定", "submit")
            End With
            e.WriteString(wb.Build)
        Else
            Dim nms() As String = {"
姓名","年龄","学历"}
           
Dim dr As DataRow = DataTables("员工").AddNew()
            For Each nm As String In nms
                dr(nm) = e.PostValues(nm)
            Next
            For Each key As String In e.Files.Keys
                If key = "up1" Then
                    For Each fln As String In e.Files(key)
                        e.SaveFile(key, fln, ProjectPath & "Attachments\\" & fln)
                    Next
                    dr.Lines("
照片") = e.Files(key)
                End If
            Next
            \'
保存并生成增加成功提示页面
            dr.save()
            With wb.AddMsgPage("","msgpage","
增加成功", "好好学习,天天向上") \'生成成功提示页
               
.AddButton("btn1","继续增加","addnew.htm")
            End With
            e.WriteString(wb.Build)
        End If

End
Select

[此贴子已经被作者于2021/8/7 17:09:19编辑过]

--  作者:有点蓝
--  发布时间:2021/8/7 17:04:00
--  
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=150626
--  作者:sunion
--  发布时间:2021/8/7 17:10:00
--  
不好意思,已更新问题,谢谢您的提醒
--  作者:有点蓝
--  发布时间:2021/8/7 17:17:00
--  
1、会覆盖掉
2、重命名参考:

For Each key As String In e.Files.Keys
    If key = "up1" Then
        Dim lst As List(of String) = dr.Lines("照片")
        For Each fln As String In e.Files(key)
            Dim n As tring = Format(Date.Now,"yyyyMMddHHmmssffff") & fln
            e.SaveFile(key, fln, ProjectPath & "Attachments\\" & n))
            lst.Add(n)
        Next
        dr.Lines("照片") = lst
    End If
Next