ASP simple file upload source code

Source: Internet
Author: User

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
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.