<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload")
Upload.SetMaxSize 100000, True
Count = Upload.Save
Set File = Upload.Files("THEFILE")
If Not File Is Nothing Then
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(".\aspupload.mdb")
Set rs = Server.CreateObject("adodb.recordset")
Hash = File.MD5Hash
rs.Open "SELECT * from MYIMAGES WHERE Hash='" & Hash & "'", Connect, 2, 3
If Not rs.EOF Then
Response.Write "This file already exists in the database."
Response.End
End If
rs.Close
rs.Open "MYIMAGES", Connect, 2, 3
rs.AddNew
rs("image_blob") = File.Binary
rs("filename") = File.FileName
rs("filesize") = File.Size
rs("hash") = Hash
rs("deion") = Upload.Form("DESCR")
rs.Update
Response.Write "File saved."
Else
Response.Write "File not selected."
End If
%>
</BODY>
</HTML>
上传及显示图片的重要代码
<%
if Trim(Request.QueryString("act")="added" ) then
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open "select * from pic",conn,1,3
Set Upload = Server.CreateObject("Persits.Upload")
Count = Upload.Save(server.mappath("/upload"))
Set File = Upload.Files("picpath")
picname = Upload.Form("picname")
picpath="upload" & "/" & file.filename
picsize=file.size
Response.Write picpath
Response.Write "您上传成功了"
rs.addnew
rs("picname")=picname
rs("picpath")=picpath
rs("picsize")=picsize
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>