There are three ways to handle file uploading with Pure ASP Uploader. You can choose one based on your application requirements.
Simple Upload
Simple Upload is designed for the simplest usage scenario. It calls the SaveDirectory method of the control which actually performs the upload. It automatically parses the information POSTed by the browser, figures out how many files are being uploaded, and saves them in a specified local directory on the server under their original names. An attachment table is also created.
- <% @ Language="VBScript" %>
- <!-- #include file="aspuploader/include_aspuploader.asp" -->
- <html>
- <body>
- <form id="form1" method="POST">
- <%
- Dim uploader
- Set uploader=new AspUploader
- uploader.Name="myuploader"
- uploader.SaveDirectory="/myfolder"
- uploader.Render()
- %>
- </form>
- </body>
- </html>
That's all that's needed. Really!
Standard ASP Upload
If your usage scenario is close to the simplest case, described above, but you need a little more control, you can use Standard ASP Upload. It allows the ASP developers to process the uploaded files using ASP code. The page posts back to itself to process the uploaded files.
- <%@ Language="VBScript" %>
- <!-- #include file="aspuploader/include_aspuploader.asp" -->
- <html>
- <head>
- </head>
- <body>
- <form id="form1" method="POST">
- <%
- Dim uploader
- Set uploader=new AspUploader
- uploader.Name="myuploader"
- uploader.Render()
- %>
- </form>
- <%
- If Request.Form("myuploader")&""<>"" Then
- Dim mvcfile
- Set mvcfile=uploader.GetUploadedFile(Request.Form("myuploader"))
- Response.Write("<div style='font-family:Fixedsys'>")
- Response.Write("Uploaded File")
- Response.Write("<br/><br/>FileName: ")
- Response.Write(mvcfile.FileName)
- Response.Write("<br/>FileSize: ")
- Response.Write(mvcfile.FileSize)
- ' Response.Write("<br/>FilePath: ")
- ' Response.Write(mvcfile.FilePath)
- Response.Write("</div>")
- End If
- %>
- </body>
- </html>
Custom file upload handler
If you need further control over the parsing of the file uploading request, you can write a custom file upload handler. In handler page (UploadUrl) developers can rename the uploaded files, process other logics programmatically.
- <%@ Language="VBScript" %>
- <!-- #include file="aspuploader/include_aspuploader.asp" -->
- <html>
- <head>
- </head>
- <body>
- <%
- Dim uploader
- Set uploader=new AspUploader
- uploader.UploadUrl="myhandler.asp"
- uploader.Render()
- %>
- </body>
- </html>
The following code shows you how to rename the uploaded files, process other logics programmatically in handler page (UploadUrl).
- <%@ Language="VBScript" %>
- <!-- #include file="aspuploader/include_aspuploader.asp" -->
- <%
- Dim uploader, mvcfile
- Set uploader=new AspUploader
- Set mvcfile=uploader.GetValidatingFile()
- If mvcfile.FileName = "some.bmp" then
- uploader.WriteValidationError("My custom error : Invalid file name. ")
- Response.End
- End if
- targetfilepath= "savefiles/myprefix_" & mvcfile.FileName
- dim fs
- Set fs=Server.CreateObject("Scripting.FileSystemObject")
- if fs.FileExists(server.mappath(targetfilepath)) then
- fs.DeleteFile(server.mappath(targetfilepath))
- end if
- set fs=nothing
- mvcfile.MoveTo( server.mappath(targetfilepath))
- uploader.WriteValidationOK()
- %>