以下为引用的内容: Inserting Form content into Database with ASP. Et2HTML5中文学习网 - HTML5先行者学习网 <% ' -- Loader.asp -- ' -- version 1.5.2 ' -- last updated 12/5/2002 ' ' Faisal Khan ' faisal@stardeveloper.com ' www.stardeveloper.com ' Class for handling binary uploads Et2HTML5中文学习网 - HTML5先行者学习网 Class Loader Private dict Private Sub Class_Initialize Set dict = Server.CreateObject("Scripting.Dictionary") End Sub Et2HTML5中文学习网 - HTML5先行者学习网 Private Sub Class_Terminate If IsObject(intDict) Then intDict.RemoveAll Set intDict = Nothing End If If IsObject(dict) Then dict.RemoveAll Set dict = Nothing End If End Sub Et2HTML5中文学习网 - HTML5先行者学习网 Public Property Get Count Count = dict.Count End Property Et2HTML5中文学习网 - HTML5先行者学习网 Public Sub Initialize If Request.TotalBytes > 0 Then Dim binData binData = Request.BinaryRead(Request.TotalBytes) getData binData End If End Sub Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFileData(name) If dict.Exists(name) Then getFileData = dict(name).Item("Value") Else getFileData = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getValue(name) Dim gv If dict.Exists(name) Then gv = CStr(dict(name).Item("Value")) gv = Left(gv,Len(gv)-2) getValue = gv Else getValue = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function saveToFile(name, path) If dict.Exists(name) Then Dim temp temp = dict(name).Item("Value") Dim fso Set fso = Server.CreateObject("Scripting.FileSystemObject") Dim file Set file = fso.CreateTextFile(path) For tPoint = 1 to LenB(temp) file.Write Chr(AscB(MidB(temp,tPoint,1))) Next file.Close saveToFile = True Else saveToFile = False End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFileName(name) If dict.Exists(name) Then Dim temp, tempPos temp = dict(name).Item("FileName") tempPos = 1 + InStrRev(temp, "/") getFileName = Mid(temp, tempPos) Else getFileName = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFilePath(name) If dict.Exists(name) Then Dim temp, tempPos temp = dict(name).Item("FileName") tempPos = InStrRev(temp, "/") getFilePath = Mid(temp, 1, tempPos) Else getFilePath = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFilePathComplete(name) If dict.Exists(name) Then getFilePathComplete = dict(name).Item("FileName") Else getFilePathComplete = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFileSize(name) If dict.Exists(name) Then getFileSize = LenB(dict(name).Item("Value")) Else getFileSize = 0 End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getFileSizeTranslated(name) If dict.Exists(name) Then temp = LenB(dict(name).Item("Value")) If temp <= 1024 Then getFileSizeTranslated = temp & " bytes" Else temp = FormatNumber((temp / 1024), 2) getFileSizeTranslated = temp & " kilobytes" End If Else getFileSizeTranslated = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Public Function getContentType(name) If dict.Exists(name) Then getContentType = dict(name).Item("ContentType") Else getContentType = "" End If End Function Et2HTML5中文学习网 - HTML5先行者学习网 Private Sub getData(rawData) Dim separator separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1) Et2HTML5中文学习网 - HTML5先行者学习网 Dim lenSeparator lenSeparator = LenB(separator) Et2HTML5中文学习网 - HTML5先行者学习网 Dim currentPos currentPos = 1 Dim inStrByte inStrByte = 1 Dim value, mValue Dim tempValue tempValue = "" Et2HTML5中文学习网 - HTML5先行者学习网 While inStrByte > 0 inStrByte = InStrB(currentPos, rawData, separator) mValue = inStrByte - currentPos Et2HTML5中文学习网 - HTML5先行者学习网 If mValue > 1 Then value = MidB(rawData, currentPos, mValue) Et2HTML5中文学习网 - HTML5先行者学习网 Dim begPos, endPos, midValue, nValue Dim intDict Set intDict = Server.CreateObject("Scripting.Dictionary") Et2HTML5中文学习网 - HTML5先行者学习网 begPos = 1 + InStrB(1, value, ChrB(34)) endPos = InStrB(begPos + 1, value, ChrB(34)) nValue = endPos Et2HTML5中文学习网 - HTML5先行者学习网 Dim nameN nameN = MidB(value, begPos, endPos - begPos) Et2HTML5中文学习网 - HTML5先行者学习网 Dim nameValue, isValid isValid = True If InStrB(1, value, stringToByte("Content-Type")) > 1 Then Et2HTML5中文学习网 - HTML5先行者学习网 begPos = 1 + InStrB(endPos + 1, value, ChrB(34)) endPos = InStrB(begPos + 1, value, ChrB(34)) Et2HTML5中文学习网 - HTML5先行者学习网 If endPos = 0 Then endPos = begPos + 1 isValid = False End If Et2HTML5中文学习网 - HTML5先行者学习网 midValue = MidB(value, begPos, endPos - begPos) intDict.Add "FileName", trim(byteToString(midValue)) Et2HTML5中文学习网 - HTML5先行者学习网 begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:")) endPos = InStrB(begPos, value, ChrB(13)) Et2HTML5中文学习网 - HTML5先行者学习网 midValue = MidB(value, begPos, endPos - begPos) intDict.Add "ContentType", trim(byteToString(midValue)) Et2HTML5中文学习网 - HTML5先行者学习网 begPos = endPos + 4 endPos = LenB(value) Et2HTML5中文学习网 - HTML5先行者学习网 nameValue = MidB(value, begPos, ((endPos - begPos) - 1)) Else nameValue = trim(byteToString(MidB(value, nValue + 5))) End If Et2HTML5中文学习网 - HTML5先行者学习网 If isValid = True Then Et2HTML5中文学习网 - HTML5先行者学习网 intDict.Add "Value", nameValue intDict.Add "Name", nameN Et2HTML5中文学习网 - HTML5先行者学习网 dict.Add byteToString(nameN), intDict End If End If Et2HTML5中文学习网 - HTML5先行者学习网 currentPos = lenSeparator + inStrByte Wend End Sub End Class Et2HTML5中文学习网 - HTML5先行者学习网 Private Function stringToByte(toConv) Dim tempChar For i = 1 to Len(toConv) tempChar = Mid(toConv, i, 1) stringToByte = stringToByte & chrB(AscB(tempChar)) Next End Function Et2HTML5中文学习网 - HTML5先行者学习网 Private Function byteToString(toConv) For i = 1 to LenB(toConv) byteToString = byteToString & Chr(AscB(MidB(toConv,i,1))) Next End Function %> Et2HTML5中文学习网 - HTML5先行者学习网 1、用户界面: <script language="JavaScript"> function CheckAll(form) {for (var i=0;i<form.elements.length;i++) {var e = form.elements[i]; if (e.name != 'chkall') e.checked = form.chkall.checked; } } </script> </head> <body> <form method="post" action="del.asp" name="form1"> <table> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件1</td> </tr> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件2</td> </tr> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件3</td> </tr> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件4</td> </tr> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件5</td> </tr> <tr> <td ><input type="checkbox" value="111" name="TradeName">电子邮件6</td> </tr> <tr> <td bgcolor="#F1FBFC" height="25" colspan="2"> <p align="left"><input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)"><font color="#FF9900">选中所有显示的消息</font></p> </td> <center> </tr> </table> </form> 2、删除文件del.asp <% '这行写连接数据库的代码 dim ID,strID strID="" For Each strID In Request.Form("TradeName") ID=Cint(strID) if strID<>"" then DelRs = Server.CreateObject("ADODB.Recordset") Conn.Execute "Delete From Tbname where ID="&Cstr(ID) strID="" end if Next Conn.Close Set Conn = Nothing Response.Redirect "成功删除!" %> Et2HTML5中文学习网 - HTML5先行者学习网 |