删除后台文件

在默认情况下,用户删除Uploader中显示的图片,并不会影响服务器中对应的的图片文件。

如果要同步删除服务器中的图片文件,我们还需要做响应的处理。

原理:

将Uploader的AllowEdit属性设置为True之后,系统会自动生成一个隐藏的输入框,这个输入框的ID是Uploader的ID加上“_deleted”。
该隐藏输入框会自动记录用户删除的图片文件,如果删除了多个图片文件,会用符号"|"分割文件名。
用户向服务端提交数据时,这个隐藏输入框的值会一并提交,服务端可以从这个值中提取出用户已经删除的文件,然后删除后台对应的文件。

一个例子:

HttpRequest事件代码:

Select Case e.Path
    Case "test.htm"
        If e.PostValues.Count = 0 Then
            Dim wb As New weui
            wb.AddForm("","form1","test.htm")
            With wb.AddInputGroup("form1","ipg1","
客户资料")
                .AddInput("
姓名","姓名","Text").value = "舒淇"
                .AddInput("
年龄","年龄","number").Value = "28"
                .AddInput("
日期","日期","date").value = #10/12/2012#
                With .AddUploader("up1","
照片",True)
                    .AllowDelete = True '
允许用户删除图片
                    .AddImage("./images/shuqi1.jpg")
                    .AddImage("./images/shuqi2.jpg")
                    .AddImage("./images/shuqi3.jpg")
                End With
            End With
            With wb.AddButtonGroup("form1","btg1",True)
                .Add("btn1", "
确定", "submit")
            End With
            e.WriteString(wb.Build) '
生成网页
        Else
            Dim sb As New StringBuilder
            sb.AppendLine("<meta name='viewport' content='width=device-width,initial-scale=1,user-scalable=0'>")
            sb.AppendLine("
已经删除了以下文件:<br/>")
            If e.PostValues.ContainsKey("up1_deleted") Then
                Dim Files = e.PostValues("up1_deleted").Split("|")
                For Each File As String In Files
                    sb.AppendLine(file & "<br/>")
                    file = "d:\web\" & File.Trim(".")
                    If Filesys.FileExists(file) Then
                        Filesys.DeleteFile(file)
                    End If
                Next
            End If
            e.WriteString(sb.ToString)
       
End If
End
Select


本页地址:http://www.foxtable.com/mobilehelp/topics/0094.htm