<!--#include file= "adoconn.asp"-->
<title> File Upload </title>
<meta name= "Description" content= "" >
<link rel= "stylesheet" href= "Manage.css" type= "Text/css" >
<body>
<%
Fuptype=session ("Fuptype") ' Upload type
Fupname=session ("fupname") ' filename
Frmname=session ("Frmname") ' form name
Bdname=session ("Bdname") ' Table Single-name
If fuptype= "" or fupname= "" or frmname= "" "Then
Response.Write "<script language= ' JavaScript ' >"
Response.Write "Alert (' Error, please upload again!") ');"
Response.Write "Location.href= ' Javascript:history.go (-1) ';"
Response.Write "</script>"
Response.End
End If
%>
<!--#include file= "Upload_5xsoft.inc"-->
<%
Set Upload=new Upload_5xsoft
Set File=upload.file ("File1")
If File.filesize>0 Then
Filename=fupname+ "."
Filenameend=file.filename
Filenameend=split (Filenameend, ".")
N=ubound (Filenameend)
Filename=filename&filenameend (N)
If fuptype<> "db" Then
If file.filesize>1572864 Then
Response.Write "<script language= ' JavaScript ' >"
Response.Write "Alert (' you upload a file too large, upload unsuccessful, single file maximum can not exceed 1500k! ');"
Response.Write "Location.href= ' Javascript:history.go (-1) ';"
Response.Write "</script>"
Response.End
End If
End If
If fuptype= "adv" or fuptype= "pic" Then
If LCase (Filenameend (n)) <> "GIF" and LCase (Filenameend (n)) <> "JPG" and LCase (Filenameend (n)) <> "Doc" and LCase (Filenameend (n)) <> "xls" and LCase (Filenameend (n)) <> "rar" and LCase (Filenameend (n)) <> zip "And LCase (Filenameend (n)) <>" TXT "then
Response.Write "<script language= ' JavaScript ' >"
Response.Write "alert (' not allowed to upload your selected file format, please check and upload again!") ');"
Response.Write "Location.href= ' Javascript:history.go (-1) ';"
Response.Write "</script>"
Response.End
End If
End If
If fuptype= "pic" Then
Savepath= ". /pic_1/"&filename
End If
File.saveas Server.MapPath (Savepath)
' Response.Write ' file uploaded successfully! The physical path to the upload file is: "
' Response.Write ' <font color=red> &server.mappath (savepath) & "</font><br><br>"
' Response.Write ' <a href= ' "&savepath&" ' target= ' _blank ' > click to preview uploaded file </a> "
' Response.Write ' <br><br><input onclick= ' javascript:window.close (); ' Type=submit value= ' upload complete ' > '
Response.Write "<script>opener.document." &frmname& "." &bdname& ". value= '" &replace (Savepath, ". /"," ") &" '; Window.close ();</script> "
%>
<%
Else
Response.Write "<script language= ' JavaScript ' >"
Response.Write Alert (' File contents cannot be empty, click OK ' to return to the previous page!) ');"
Response.Write "Location.href= ' Javascript:history.go (-1) ';"
Response.Write "</script>"
Response.End
End If
Set upload=nothing
Session ("Fuptype") = ""
Session ("fupname") = ""
Session ("frmname") = ""
%>
</body>
The following is the Upload_5xsoft.inc file to download and save this code directly
<script Runat=server language=vbscript>
Dim Upfile_5xsoft_stream
Class Upload_5xsoft
Dim form,file,version
Private Sub Class_Initialize
Dim istart,ifilenamestart,ifilenameend,iend,vbenter,iformstart,iformend,thefile
Dim strdiv,mformname,mformvalue,mfilename,mfilesize,mfilepath,idivlen,mstr
Version= "Transformation programming HTTP Upload Program Version 1.0"
If Request.totalbytes<1 then Exit Sub
Set Form=createobject ("Scripting.Dictionary")
Set File=createobject ("Scripting.Dictionary")
Set Upfile_5xsoft_stream=createobject ("ADODB.stream")
Upfile_5xsoft_stream.mode=3
Upfile_5xsoft_stream.type=1
Upfile_5xsoft_stream.open
Upfile_5xsoft_stream.write Request.BinaryRead (request.totalbytes)
VBENTER=CHR (&CHR) (10)
Idivlen=instring (1,vbenter) +1
Strdiv=substring (1,idivlen)
Iformstart=idivlen
Iformend=instring (Iformstart,strdiv)-1
While Iformstart < Iformend
Istart=instring (Iformstart, "name=" "")
Iend=instring (Istart+6, "" "")
Mformname=substring (istart+6,iend-istart-6)
Ifilenamestart=instring (iend+1, "filename=" "")
If Ifilenamestart>0 and Ifilenamestart<iformend then
Ifilenameend=instring (ifilenamestart+10, "" "")
Mfilename=substring (IFILENAMESTART+10,IFILENAMEEND-IFILENAMESTART-10)
Istart=instring (Ifilenameend+1,vbenter&vbenter)
Iend=instring (Istart+4,vbenter&strdiv)
If Iend>istart Then
Mfilesize=iend-istart-4
Else
Mfilesize=0
End If
Set Thefile=new FileInfo
Thefile.filename=getfilename (Mfilename)
Thefile.filepath=getfilepath (Mfilename)
Thefile.filesize=mfilesize
Thefile.filestart=istart+4
Thefile.formname=formname
File.add Mformname,thefile
Else
Istart=instring (Iend+1,vbenter&vbenter)
Iend=instring (Istart+4,vbenter&strdiv)
If Iend>istart Then
Mformvalue=substring (istart+4,iend-istart-4)
Else
Mformvalue= ""
End If
Form. ADD Mformname,mformvalue
End If
Iformstart=iformend+idivlen
Iformend=instring (Iformstart,strdiv)-1
Wend
End Sub
Private Function subString (Thestart,thelen)
Dim i,c,stemp
Upfile_5xsoft_stream.position=thestart-1
Stemp= ""
For I=1 to TheLen
If Upfile_5xsoft_stream.eos then Exit for
C=ASCB (Upfile_5xsoft_stream.read (1))
If C > 127 Then
If Upfile_5xsoft_stream.eos then Exit for
STEMP=STEMP&CHRW (AscW (ChrB (AscB (Upfile_5xsoft_stream.read (1)) &CHRB (c)))
I=i+1
Else
STEMP=STEMP&CHR (c)
End If
Next
Substring=stemp
End Function
Private Function instring (THESTART,VARSTR)
Dim i,j,bt,thelen,str
Instring=0
Str=tobyte (VARSTR)
Thelen=lenb (STR)
For I=thestart to Upfile_5xsoft_stream.size-thelen
If I>upfile_5xsoft_stream.size then Exit Function
Upfile_5xsoft_stream.position=i-1
If AscB (Upfile_5xsoft_stream.read (1)) =ASCB (MidB (str,1)) Then
Instring=i
For j=2 to TheLen
If Upfile_5xsoft_stream.eos Then
Instring=0
Exit for
End If
If AscB (Upfile_5xsoft_stream.read (1)) <>ASCB (MidB (str,j,1)) Then
Instring=0
Exit for
End If
Next
If Instring<>0 then Exit Function
End If
Next
End Function
Private Sub class_terminate
form. RemoveAll
file. RemoveAll
Set form=nothing
set file=nothing
Upfile_5xsoft_stream.close
set up File_5xsoft_stream=nothing
End Sub
private function GetFilePath (fullpath)
If fullpath <> "Then
GetFilePath = Left (Fullpath,instrrev (FullPath," "))
E LSE
GetFilePath = "
end If
End function
private function GetFileName (fullpath)
If fullpath <> "" Then
GetFileName = Mid (Fullpath,instrrev (FULLP Ath, "") +1
Else
getfilename = "
end If
End function
Private function ToByte (STR)
Dim I,icode,c,ilow,ihigh
Tobyte= ""
For I=1 to Len (STR)
C=mid (str,i,1)
Icode =ASC (c)
If icode<0 Then icode = Icode + 65535
If icode>255 Then
Ilow = Left (Hex (ASC (c)), 2)
Ihigh =right (Hex (ASC (c)), 2)
ToByte = ToByte & ChrB ("&h" &ilow) & ChrB ("&h" &ihigh)
Else
ToByte = ToByte & ChrB (AscB (c))
End If
Next
End Function
End Class
Class FileInfo
Dim Formname,filename,filepath,filesize,filestart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
filestart= 0
FormName = ""
End Sub
Public Function SaveAs (fullpath)
Dim dr,errorchar,i
Saveas=1
If trim (fullpath) = "" or filesize=0 or filestart=0 or filename= "" Then Exit function
If Filestart=0 or right (fullpath,1) = "/" Then Exit function
Set Dr=createobject ("ADODB.stream")
Dr. Mode=3
Dr. Type=1
Dr. Open
Upfile_5xsoft_stream.position=filestart-1
Upfile_5xsoft_stream.copyto dr,filesize
Dr. SaveToFile fullpath,2
Dr. Close
Set dr=nothing
Saveas=0
End Function
End Class
</SCRIPT>