File 1. Upload the interface file upload.htm
<HTML>
<Head>
<Meta http-equiv = "content-language" content = "ZH-CN">
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> File Upload </title>
</Head>
<Body>
<Form method = "Post" Action = "SaveFile. asp">
File Upload: <input type = "file" name = "file" size = "42"> & nbsp; <input type = "Submit" value = "Submit" name = "BB">
</Form>
</Body>
</Html>
File 2. Save the SaveFile. asp
<%
Dim file, filename, houzui
File = request. Form ("file ")
If file = "" then
Response. Write "<SCRIPT> alert ('select the file to upload! '{{{Location.href}'upload.htm'; </SCRIPT>"
Else
Houzui = mid (file, cmdrev (file ,"."))
If houzui = ". GIF" or houzui = ". jpg" or houzui = ". BMP" then' indicates the file type that can be uploaded.
Filename = year (date) & month (date) & Day (date) & hour (time) & minute (time) & Second (time) & houzui
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1
Objstream. Open
Objstream. loadfromfile File
Objstream. savetofile server. mappath (filename), 2
Objstream. Close
// ============================== Write the file name to the database, if not required, this code segment can be deleted!
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("mb. mdb ")
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * From IMG", Conn, 1, 2
Rs. addnew
RS ("name") = filename
Rs. Update
Set rs = nothing
Conn. Close
Set conn = nothing
// ================================================ =
Response. Write "<SCRIPT> alert ('image uploaded successfully! '{{{Location.href}'upload.htm'; </SCRIPT>"
Else
Response. Write "<SCRIPT> alert ('upload prohibited" & houzui & "format! '{{{Location.href}'upload.htm'; </SCRIPT>"
End if
End if
%>