Asp uploads local files to the server and asp files to the server

Source: Internet
Author: User

Asp uploads local files to the server and asp files to the server

Today, we will explain how to use asp's upload function to upload local files to the server.
The simplest system includes the following three files:

Upload.htm -- upload port file, select local file
Uploadimg. asp -- upload a program control file
Upload_5xsoft.inc -- no component upload class. This file is not required for beginners. You only need to use it.

Upload.htm content ---- upload port file, select local file

<Html> 

Uploadimg. asp content ---- upload a program control file

<! -- # Include FILE = "upload_5xsoft.inc" --> <% dim upload, file, filepathfilepath = "UPLOAD/" set upload = new upload_5xSoft '': creates an upload object for each formName in upload. file ''lists all uploaded files. set file = upload. file (formName) ''generates a file object if file. fileSize> 0 then'' if FileSize> 0, there is file data fname = file. filename file. saveAs Server. mappath (filepath & fname) ''saves the end ifset file = nothingnextset upload = nothing'' to delete this object

Upload_5xsoft.inc content---- The content of this document does not belong to this drill program. This drill applies this method.

<Script runat = server language = VBSCRIPT> dim oUpFileStreamClass upload_5xSoft dim Form, File, Version Private Sub Class_Initialize dim RequestBinDate, sStart, bCrLf, sInfo, iInfoStart, iInfoEnd, tStream, iStart, oFileInfodim iFileSize, sFilePath, sFileType, sFormvalue, sFileNamedim iFindStart, iFindEnddim iFormStart, iFormEnd, sFormNameVersion = "no component upload class Version 0.93" set Form = Server. createObject ("Scripting. dictionary ") set File = Server. createObject ("Scripting. dictionary ") if Request. totalBytes <1 then Exit Subset tStream = Server. createObject ("adodb. stream ") set oUpFileStream = Server. createObject ("adodb. stream ") oUpFileStream. type = 1oUpFileStream. mode = 3oUpFileStream. openoUpFileStream. write Request. binaryRead (Request. totalBytes) Response. write "<font size =" 2 "> page execution time:" & FormatNumber (Timer ()-time1) *, 3) & "millisecond </font> <br>" oUpFileStream. position = 0 RequestBinDate = oUpFileStream. read iFormStart = 1 iFormEnd = LenB (RequestBinDate) bCrLf = chrB (13) & chrB (10) sStart = MidB (RequestBinDate, 1, Region B (iFormStart, RequestBinDate, bCrLf)-1) iStart = LenB (sStart) iFormStart = iFormStart + iStart + 1 while (iFormStart + 10) <iFormEnd iInfoEnd = InStrB (iFormStart, RequestBinDate, bCrLf & bCrLf) + 3 tStream. type = 1 tStream. mode = 3 tStream. open oUpFileStream. position = iFormStart oUpFileStream. copyTo tStream, iInfoEnd-iFormStart tStream. position = 0 tStream. type = 2 tStream. charset = "gb2312" sInfo = tStream. readtext' get the form project name iFormStart = Member B (iInfoEnd, RequestBinDate, sStart) iFindStart = InStr (22, sInfo, "name =", 1) + 6 iFindEnd = InStr (iFindStart, sInfo, ", 1) sFormName = Mid (sinfo, iFindStart, iFindEnd-iFindStart) 'if it is a file if InStr (45, sInfo, "filename =", 1)> 0 then set oFileInfo = new FileInfo 'get the file name iFindStart = InStr (iFindEnd, sInfo, "filename =", 1) + 10 iFindEnd = InStr (iFindStart, sInfo, ", 1) sFileName = Mid (sinfo, iFindStart, iFindEnd-iFindStart) oFileInfo. fileName = getFileName (sFileName) oFileInfo. filePath = getFilePath (sFileName) 'get the file Type iFindStart = InStr (iFindEnd, sInfo, "Content-Type:", 1) + 14 iFindEnd = InStr (iFindStart, sInfo, vbCr) oFileInfo. fileType = Mid (sinfo, iFindStart, iFindEnd-iFindStart) oFileInfo. fileStart = iInfoEnd oFileInfo. fileSize = iFormStart-iInfoEnd-3 oFileInfo. formName = sFormName file. add sFormName, oFileInfo else 'if it is a Form Project tStream. close tStream. type = 1 tStream. mode = 3 tStream. open oUpFileStream. position = iInfoEnd oUpFileStream. copyTo tStream, iFormStart-iInfoEnd-3 tStream. position = 0 tStream. type = 2 tStream. charset = "gb2312" sFormvalue = tStream. readText form. add sFormName, sFormvalue end if tStream. close iFormStart = iFormStart + iStart + 1 wendRequestBinDate = "" set tStream = nothingEnd SubPrivate Sub Class_Terminate if not Request. totalBytes <1 then form. removeAll file. removeAll set form = nothing set file = nothing oUpFileStream. close set oUpFileStream = nothing end ifEnd Sub Private function GetFilePath (FullPath) If FullPath <> "" Then GetFilePath = left (FullPath, limit Rev (FullPath ,"")) else GetFilePath = "" End If End function Private function GetFileName (FullPath) If FullPath <> "" Then GetFileName = mid (FullPath, limit Rev (FullPath, "") + 1) else GetFileName = "" End If End functionEnd ClassClass FileInfo dim FormName, FileName, FilePath, FileSize, FileType, fileStart Private Sub Class_Initialize FileName = "" FilePath = "" FileSize = 0 FileStart = 0 FormName = "" FileType = "" End Sub Public function SaveAs (FullPath) dim oFileStream, ErrorChar, I SaveAs = 1 if trim (fullpath) = "" or right (fullpath, 1) = "/" then exit function set oFileStream = CreateObject ("Adodb. stream ") oFileStream. type = 1 oFileStream. mode = 3 oFileStream. open oUpFileStream. position = FileStart oUpFileStream. copyto oFileStream, FileSize oFileStream. saveToFile FullPath, 2 oFileStream. close set oFileStream = nothing SaveAs = 0 end functionEnd Class </SCRIPT>

The content mentioned in this article is the most simplified program for uploading files. Please analyze it yourself and learn this walkthrough. The general asp upload function is basically mastered.

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.