Click here to Skip to main content
15,896,432 members
Articles / Programming Languages / ASP

File Upload using a VBScript Class

Rate me:
Please Sign up or sign in to vote.
4.91/5 (48 votes)
29 May 20022 min read 394.8K   9K   63  
Using a VBScript class to upload files. Useful when you are not able to deploy a custom COM object.
<%@ Language=VBScript %>
<!-- #include file="vbsUpload.asp" -->
<!-- #include file="conn.asp" -->

<form method=post
      enctype="multipart/form-data"
      action=Process_DB.asp>
Your File:<BR><input type=file name=YourFile><BR><BR>
<input type=submit name=submit value="Upload">
</form>

<%
Dim objUpload,DB

If Request.TotalBytes > 0 Then
	Set objUpload = New vbsUpload
	DB = "doc_warhouse"

' Make a note that doc_id column IDENTITY is set. So the id will be generated automatically
				getsql = true																	
				if getdata("select top 0 * from " & DB,RS) > -1 then
					rs.AddNew 
					rs.Fields("doc_name") = objUpload.Files.Item(0).FileName
					rs.Fields("doc_type") = objUpload.Files.Item(0).ContentType
					RS("doc_data").AppendChunk objUpload.Files.Item(0).Blob
					rs.Update 

				Else 
					Response.Write "Error"
					Response.End
				end if
				
				getsql = false

				if getdata("select max(doc_id) as docs from " & DB,RS) > -1 then
				Response.redirect "download.asp?doc_id="&RS("docs").value
				End if
End if

%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Hong Kong Hong Kong
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions