This is a file named upload _ wj.inc. Copy the code with Notepad and save it as upload _ wj.inc.
& lt%
-
Please keep this statement information when forwarding, this statement will not affect your speed!
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Modified by: Yu Bin
E-mail:
Website:
Original author: Daoxiang old farmer
Original author's website:
Disclaimer: This upload class is modified on the basis of the component-free upload class published by the environmental programming community.
Compared with uploading componentless classes in the field of environmental programming, it is nearly 50 times faster. When uploading a file with a size of 4M,
The processing time of the server is only 10 second. Is currently the fastest upload program without components, and the current version is 0.96.
The source code is open and can be used for free. For commercial use, please contact the author.
File properties: for example, the uploaded file is c: \ myfile \ doc.txt.
File name File name string "doc.txt"
File size value 12 10
File type File type string "text/plain"
FileExt file extension string "txt"
File path file original path string "c:\myfile"
Matters needing attention when using:
Because the script. Dictionaries are case-sensitive, and the names of entries in web pages and ASP pages should be the same.
Write, if people are used to using uppercase or lowercase, in order to prevent mistakes, you can put
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
Change to'
(lowercase) sformname = lcase (mid (ifindend-ifindstart, ifindstart))
(capital) sformName = ucase (Mid (ifindend-ifindstart, ifindstart))
'**********************************************************************
-
Dim output file stream
Course Upload _ File
Dim forms, files, versions
Private subclass _Initialize
defined variable
dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Code start
Version= "Uploaded class version 0.96 without components"
Setup Form = Server. CreateObject ("script. Dictionary ")
Settings file = server. CreateObject ("script. Dictionary ")
If required. TotalBytes & lt 1 and then exit the connector.
Set tStream = Server. CreateObject("adodb.stream ")
set oUpFileStream = Server。 CreateObject("adodb.stream ")
oUpFileStream。 Type = 1
oUpFileStream。 Mode = 3
oUpFileStream。 open
oUpFileStream。 Write a request. BinaryRead (request. Total bytes)
oUpFileStream。 Location =0
RequestBinDate = oUpFileStream。 read
iFormEnd = oUpFileStream。 size
bCrLf = chrB( 13)chrB( 10)
Gets the separator between items.
sStart = MidB(RequestBinDate, 1,InStrB( 1,RequestBinDate,bCrLf)- 1)
iStart = LenB (sStart)
iFormStart = iStart+2
Decomposition project
do
iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & ampbCrLf)+3
tStream。 Type = 1
tStream。 Mode = 3
tStream。 open
oUpFileStream。 Position = iFormStart
oUpFileStream。 Copy to tStream, iInfoEnd-iFormStart
tStream。 Location = 0
tStream。 Type = 2
tStream。 Charset ="gb23 12 "
sInfo = tStream。 Read the text
Gets the name of the form item.
iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart)- 1
iFindStart = InStr(22,sInfo," name= " ", 1)+6
iFindEnd = InStr(iFindStart,sInfo,"""", 1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
If it's a file.
If InStr (45, sInfo, "filename=" ",1) > then 0.
Set oFileInfo= new file information
Get document properties
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)
oFileInfo。 FileExt = GetFileExt(sFileName)
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 -2
oFileInfo。 FormName = sFormName
file.add sFormName,oFileInfo
other
If it is a form item.
tStream。 close
tStream。 Type = 1
tStream。 Mode = 3
tStream。 open
oUpFileStream。 Position = iInfoEnd
oUpFileStream。 Copy to tStream, iFormStart-iInfoEnd-2
tStream。 Location = 0
tStream。 Type = 2
tStream。 Charset = "gb23 12 "
sFormvalue = tStream。 Read the text
Form. Add sFormName, sFormvalue
If ... it will be over.
tStream。 close
iFormStart = iFormStart+iStart+2
If you reach the end of the file, please exit.
Loop until (iFormStart+2) = iFormEnd.
RequestBinDate= " "
Set tStream = nothing.
End joint
Private Subclass _ Termination
Clear variables and objects.
If there is no request. TotalBytes & lt then 1
oUpFileStream。 close
set oUpFileStream =nothing
If ... it will be over.
Form. Delete all
Documents. Delete all
Set Form = None
Settings file = None
End joint
Get the file path.
Private function GetFilePath(FullPath)
If full path < > ""then
GetFilePath = left(FullPath,InStrRev(FullPath," \ "))
other
GetFilePath = " "
If ... it will be over.
End function
Get file name
Private function GetFileName (full path)
If full path < > ""then
GetFileName = mid(FullPath,InStrRev(FullPath," \")+ 1)
other
GetFileName = " "
If ... it will be over.
End function
Pick up the extension
Private function GetFileExt (full path)
If full path < > ""then
GetFileExt = mid(FullPath,InStrRev(FullPath," ")+ 1)
other
GetFileExt = " "
If ... it will be over.
End function
End class
File attribute class
FileInfo class
Dim format name, file name, file path, file size, file type, file start, file extension.
Private subclass _Initialize
File name = ""
File path = ""
File size = 0
File start = 0
FormName = " "
File type = ""
FileExt = " "
End joint
File saving method
Common function SaveToFile (full path)
dim oFileStream,ErrorChar,I
SaveToFile= 1
If trim(fullpath)= ""or right(fullpath, 1)="/ ",the function will be exited.
set of ilestream = CreateObject(" Adodb。 Stream ")
oFileStream。 Type= 1
oFileStream。 Mode =3
oFileStream。 open
oup filestream . position = FileStart
oup filestream . copy to of ilestream,FileSize
oFileStream。 SaveToFile full path, 2
oFileStream。 close
set oFileStream=nothing
SaveToFile=0
End function
End class
% & gt
Below is a nested page.
Nesting with the following code
& ltiframe src = " situjiaduotu . ASP " align = " left " width = " 300 " height = " 25 " scrolling = " no " frame border = " 0 " & gt; & lt/iframe & gt;
This is the situjiaduotu.asp document.
& lt%
Uppath="upfile/ "'file upload path, which is very important. You should create an upfile folder in the root directory of the server.
Filelx="jpg "'Request ("file LX ")' File upload type
FormName=request("formName ")' Returns the name of the form where the edit box is located on the previous page.
EditName=request("EditName ")' returns to the name of the edit box on the previous page.
% & gt
& lt scripting language = "javascript">
& lt! -
Function mysub ()
{
esave . style . visibility = " visible ";
}
-& gt;
& lt/script & gt; & ltstyle type="text/css " >
& lt! -
Text {
Left margin: 0px
Margin-Top: 0px
Right margin: 0px
Margin-bottom: 0px
}
-& gt;
& lt/style & gt;
& ltform name = " form 2 " method = " post " action = " situjiaduotu 2 . ASP " enctype = " multipart/form-data " target = " _ blank " & gt;
& lt Table width =300 height =" 15" BORDER=0 Cell spacing =0 Cell padding = 0>
& lttr & gt
& lttd align="left" id="upid" >。
& ltinput type = " file " name = " file 1 " size = " 25 " class = " tx 1 " value = " " & gt; & ltinput type = " submit " name = " submit " value = " upload " class = " button " onclick = " JavaScript:mysub()" >
& ltinput type = " hidden " name = " file path " value = " & lt; %=uppath% >& gt
& ltinput type = " hidden " name = " filel x " value = " & lt; % = filelx % >& gt
& ltinput type = " hidden " name = " EditName " value = " & lt; % = edit name% >& gt
& ltinput type = " hidden " name = " FormName " value = " & lt; %=formName% >& gt
& ltinput type = " hidden " name = " act " value = " upload file " & gt。 & lt/font & gt; & lt/b & gt;
& lt/TD & gt;
& lt/tr & gt;
& lt/table & gt;
& lt/form & gt;
This is the situjiaduotu2.asp document.
& lt! -# include file = " upload _ wj . Inc "-& gt;
& ltlink href = " CSS . CSS " rel = " style sheet " type = " text/CSS " >
& lt%
Set upload = newly uploaded file.
If upload.form("act")="uploadfile ",then
file path = trim(upload . form(" file path "))
filel x = trim(upload . form(" filel x "))
i=0
For each form name in the upload. document
Set file = upload. File (Form Name)
File extension obtained by fileExt=lcase(file). "FileExt" does not contain.
If file.filesize & lt Then 100
Response.write "< scripting language = javascript & gtAlert ('Please select the file you want to upload first!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
if(file LX & lt; > "swf") and (file LX < > "jpg") and then
Response.write "< scripting language = javascript & gtAlert ('This file type cannot be uploaded!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
If filelx="swf ",then
If fileext & lt& gt then "sovereign wealth fund"
Response.write "< scripting language = javascript & gtAlert ('Only Flash files in swf format can be uploaded!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
If ... it will be over.
If filelx="jpg ",then
If fileext & lt& gt "GIF" and fileext & lt> "jpg" then.
Response.write "< scripting language = javascript & gtAlert ('Only pictures in jpg or gif format can be uploaded!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
If ... it will be over.
If filelx="swf ",then
Iffile.filesize & gt (3000 *1024) and then
Response.write "< scripting language = javascript & gtAlert('Flash file size cannot exceed 3m!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
If ... it will be over.
If filelx="jpg ",then
Iffile.filesize & gt (1000 *1024) and then
Response.write "< scripting language = javascript & gtAlert ('Image file size cannot exceed 1m!' ); history . go(- 1); & lt/script & gt; "
Response. End
If ... it will be over.
If ... it will be over.
Irregular
ranNum = int(90000 * rnd)+ 10000
File name = file path & year (now) and. Month (now) and. Day (present) and time; Hours (now) & minutes (now) & second time (now) & Lanham & "."& file extension
% & gt
& lt%
If the file. File size & gt0then'' iffilesize >; 0 means there is file data.
File.saveasserver.mappath (filename)'' Save the file.
Documents. SaveToFile Server.mappath (file name)
The file name of the response.write file & "Uploaded successfully! & ltbr >;
Response.write "New file:&; File name & amp“& ltbr >;;
The new file name "response.write" has been copied to the required location, so you can close the window! "
If filelx="swf ",then
Response.write "< script & gtwindow.opener.document upload . form(" FormName ")& amp;" . size.value =' "&int (file. FileSize/ 1024)& amp; K ' & lt/script & gt; "
If ... it will be over.
Response.write "< script & gtwindow.opener.document upload . form(" FormName ")& amp;" ."& ampupload . form(" EditName ")& amp;" . value =' "& file name and "
% & gt
& lt%
If ... it will be over.
Settings file = None
then
Set upload = None
If ... it will be over.
Session ("file name") = file name
Conversation. Timeout =20
% & gt
& lt scripting language = "javascript">
Window.alert ("File uploaded successfully! Please do not modify the generated link address! ”);
window . opener . location . onsubmit = " refresh()"; ;
window.close()。
& lt/script & gt;
Finally, be sure to create a folder named upfile in the root directory of the server! This is very important!
Add to the file written to the database
Rs ("imgur") = session ("file name")
Answer finished ~ remember to give me extra points!