ASP Upload Usage Instructions

Source: Internet
Author: User
Tags object count end file upload sql readfile client microsoft frontpage
Uploading to a Web server using ASP implementation files
AspUpload version 2.0, the relevant source files are as follows (uploadtest.htm):

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> File Upload Client </title>
<body>
<form method= "POST" action= "uploadtest1.asp" enctype= "Multipart/form-data"
Name= "Uploadform" >
<p><input type= "File" name= "File1" > </p>
<p><input type= "Submit" value= "Submit" Name= "Upload" ></p>
</form>
</body>
Where the client file should pay attention to two points:
* The enctype of the File Upload Submission form (form) must be specified as "Multipart/form-data"
* Statement <input type= "file" name= "File1" > indicates that the file domain is uploaded, and users can enter or select files in that field.
The server-side source files are as follows (uploadtest1.asp):
<%response.buffer=true%>
<%set upload=server.createobject ("Persits.upload.1") ' Create a File Upload component
Count=upload.save ("E:\aspupload") ' Saves the client file to the local hard drive on the Web server side%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>upload test</title>
<meta name= "generator" content= "Microsoft FrontPage 3.0" >
<body>
<p> uploaded <%=Count%> files </p>
<p>file has been uploaded.</p>
</body>
where script set Upload=server.createobject ("Persits.upload.1") creates a file upload component that saves the contents of the browser-side file to the specified path by calling the Save method.

the file exists in the database
Saving a file in a database mainly uses the Todatabase method of the file object in the AspUpload component. The source files are as follows:
Client source file (uploadtodb.htm):
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> File Upload Client </title>
<body>
<form method= "POST" action= "uploadtodb.asp" enctype= "Multipart/form-data"
Name= "Formupload" >
<p><input type= "File" name= "FileUpload" > </p>
<p><input type= "Submit" value= "Upload" name= "B1" ></p>
</form>
<p><a href= "readfile.asp" > read files in database </a></p>
</body>
server-side source files (uploadtodb.asp):
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> file upload to database </title>
<body>
<%set upload=server.createobject ("Persits.upload.1")
Count=upload.save ("E:\aspupload")
On Error Resume Next
Set Fileobj=upload.files ("FileUpload")
sql= INSERT INTO UploadFile (title,filename,content) VALUES (' &FileObj.Path& ', ' &FileObj.Path& ', ?)"
Response.Write SQL
Fileobj.todatabase "Dsn=fileupload; Uid=sa; ", SQL
If Err<>0 Then
Response.Write "Error Saving the file:" &err.description
Else
Fileobj.delete
Response.Write "Success!"
End If
%>
</body>

read the contents of the file from the database and send it to the client browser
Read content from a database before you send it to the browser, you must first let the browser know the data type of the content, which is implemented by sending a contenttype description to the client. For simplicity, this assumes that the content sent is a Word document and displays the most recently inserted record. The source files are as follows:
The client source file is uploadtodb.htm (the client file in the previous section).
Server-side source files (readfile.asp):

<%response.expires = 0
Response.buffer=true%>
<%response.clear
Response.ContentType = "Application/msword"
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Dsn=fileupload; Uid=sa; "
Set Rs1=conn.execute ("Select Maxid=max (ID) from UploadFile")
Sql= "SELECT * from UploadFile where id=" &rs1 ("Maxid")
Set Rs=conn.execute (SQL)
Response.BinaryWrite rs ("Content")
Rs.close
Rs1.close
Conn.close
Response.End
%>
Where the WEB server sends a content-type= "Application/msword" to the client that the client considers to be a Word document, and then the server reads the contents of the file from the database (for simplicity, assuming the last record in the database), It is then sent as a binary stream to the client (invoking the BinaryWrite method of the ASP built-in object response). When the client receives the content, it automatically starts the Word OLE service, which embeds the word control into the formatted display of the content that is received in browser ie.

Related Article

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.