📄 upfilesave.asp
字号:
UpFileObj.File(FormNameItem).SaveToFile FilePath &FileName
TempFileStr=TempFileStr & FormPath & FileName & "|"
If AddWaterFlag = "1" Then '在保存好的图片上添加水印
call T.AddWaterMark(FilePath & FileName)
End if
CurrNum=CurrNum+1
IF CreateThumbsFlag=true and (cint(CurrNum)=cint(DefaultThumb) or BasicType=2) Then
If TBSetting(0)=0 then
if ThumbPathFileName="" then
ThumbPathFileName=FormPath &FileName
Else
ThumbPathFileName=ThumbPathFileName & "|" & FormPath & FileName
End If
Else
ThumbFileName=split(FileName,".")(0)&"_S."&FileExtName
call T.CreateThumbs(FilePath & FileName,FilePath & ThumbFileName)
'取得缩略图地址
if ThumbPathFileName="" then
ThumbPathFileName=FormPath & ThumbFileName
else
ThumbPathFileName=ThumbPathFileName & "|" & FormPath & ThumbFileName
end if
End If
End if
End Function
End Class
Dim UpFileStream
Class UpFileClass
Dim Form,File,Err
Private Sub Class_Initialize
Err = -1
End Sub
Private Sub Class_Terminate
'清除变量及对像
If Err < 0 Then
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
UpFileStream.Close
Set UpFileStream = Nothing
End If
End Sub
Public Property Get ErrNum()
ErrNum = Err
End Property
Public Sub GetData ()
'定义变量
Dim RequestBinData,sSpace,bCrLf,sObj,iObjStart,iObjEnd,tStream,iStart,oFileObj
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
'代码开始
If Request.TotalBytes < 1 Then '如果没有数据上传
Err = 1
Exit Sub
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 UpFileStream = Server.CreateObject ("ADODB.Stream")
UpFileStream.Type = 1
UpFileStream.Mode = 3
UpFileStream.Open
UpFileStream.Write (Request.BinaryRead(Request.TotalBytes))
UpFileStream.Position = 0
RequestBinData=UpFileStream.Read
iFormEnd = UpFileStream.Size
bCrLf = ChrB (13) & ChrB (10)
'取得每个项目之间的分隔符
sSpace=MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1)
iStart=LenB (sSpace)
iFormStart = iStart+2
'分解项目
Do
iObjEnd=InStrB(iFormStart,RequestBinData,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
UpFileStream.Position = iFormStart
UpFileStream.CopyTo tStream,iObjEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sObj = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB (iObjEnd,RequestBinData,sSpace)-1
iFindStart = InStr (22,sObj,"name=""",1)+6
iFindEnd = InStr (iFindStart,sObj,"""",1)
sFormName = Mid (sObj,iFindStart,iFindEnd-iFindStart)
'如果是文件
If InStr (45,sObj,"filename=""",1) > 0 Then
Set oFileObj = new FileObj_Class
'取得文件属性
iFindStart = InStr (iFindEnd,sObj,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sObj,"""",1)
sFileName = Mid (sObj,iFindStart,iFindEnd-iFindStart)
oFileObj.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1)
oFileObj.FilePath = Left (sFileName,InStrRev (sFileName, "\"))
oFileObj.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)
iFindStart = InStr (iFindEnd,sObj,"Content-Type: ",1)+14
iFindEnd = InStr (iFindStart,sObj,vbCr)
oFileObj.FileType = Mid (sObj,iFindStart,iFindEnd-iFindStart)
oFileObj.FileStart = iObjEnd
oFileObj.FileSize = iFormStart -iObjEnd -2
oFileObj.FormName = sFormName
File.add sFormName,oFileObj
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
UpFileStream.Position = iObjEnd
UpFileStream.CopyTo tStream,iFormStart-iObjEnd-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
RequestBinData = ""
Set tStream = Nothing
End Sub
End Class
'----------------------------------------------------------------------------------------------------
'文件属性类
Class FileObj_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
UpFileStream.Position = FileStart
UpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Path,2
oFileStream.Close
Set oFileStream = Nothing
End Function
'取得文件数据
Public Function FileData
UpFileStream.Position = FileStart
FileData = UpFileStream.Read (FileSize)
End Function
End Class
'**************************************************
'函数名:ReturnChannelAllowUpFilesTF
'作 用:返回频道的是否允许上传文件
'参 数:ChannelID--频道ID
'**************************************************
Public Function ReturnChannelAllowUpFilesTF(ChannelID)
If ChannelID = "" Or Not IsNumeric(ChannelID) Then ChannelID = 0
Dim CRS:Set CRS=Server.CreateObject("ADODB.RECORDSET")
CRS.Open "Select UpFilesTF From KS_Channel Where ChannelID=" & ChannelID, Conn, 1, 1
If CInt(ChannelID) = 0 Or (CRS.EOF And CRS.BOF) Then '默认允许上传文件
ReturnChannelAllowUpFilesTF = True
Else
If CRS(0) = 1 Then ReturnChannelAllowUpFilesTF = True Else ReturnChannelAllowUpFilesTF = False
End If
CRS.Close:Set CRS = Nothing
End Function
'**************************************************
'函数名:ReturnChannelUpFilesDir
'作 用:返回频道后台的上传目录
'参 数:ChannelID--频道ID
'返回值:目录字符串
'**************************************************
Public Function ReturnChannelUpFilesDir(ChannelID)
If ChannelID = "" Or Not IsNumeric(ChannelID) Then
ReturnChannelUpFilesDir = Setting(91)
Exit Function
End If
ReturnChannelUpFilesDir = replace(Setting(3) & C_S(ChannelID,24),"//","/")
ReturnChannelUpFilesDir = Left(ReturnChannelUpFilesDir, Len(ReturnChannelUpFilesDir) - 1)
End Function
'**************************************************
'函数名:ReturnChannelAllowUserUpFilesTF
'作 用:返回频道是否允许会员上传文件
'参 数:ChannelID--频道ID
'**************************************************
Public Function ReturnChannelAllowUserUpFilesTF(ChannelID)
If ChannelID = "" Or Not IsNumeric(ChannelID) Then '默认允许上传文件
ReturnChannelAllowUserUpFilesTF = True:Exit Function
End If
If C_S(ChannelID,26) = 1 Then
ReturnChannelAllowUserUpFilesTF = True
Else
ReturnChannelAllowUserUpFilesTF = False
End If
End Function
'**************************************************
'函数名:ReturnChannelUserUpFilesDir
'作 用:返回频道前台会员的上传目录
'参 数:ChannelID--频道ID,UserFolder-按用户名生成的目录
'返回值:目录字符串
'**************************************************
Public Function ReturnChannelUserUpFilesDir(ChannelID,UserFolder)
Dim Ce:Set Ce=new CtoeCls
UserFolder=Ce.CTOE(R(UserFolder))
Set Ce=Nothing
ChannelID = ChkCLng(ChannelID)
Select Case ChannelID
Case 9999 '用户头像
ReturnChannelUserUpFilesDir=Setting(3)&Setting(91)&"User/" & UserFolder &"/upface/"
Case 9998 '相册封面
ReturnChannelUserUpFilesDir=Setting(3)&Setting(91)&"User/" & UserFolder &"/xc/"
Case 9997 '照片
ReturnChannelUserUpFilesDir=Setting(3)&Setting(91)&"User/" & UserFolder &"/xc/"
Case 9996 '圈子图片
ReturnChannelUserUpFilesDir=Setting(3)&Setting(91)&"User/" & UserFolder &"/team/"
Case Else
ReturnChannelUserUpFilesDir = C_S(ChannelID,27)
ReturnChannelUserUpFilesDir = Setting(3) & Setting(91)&"User/" & UserFolder &"/"& ReturnChannelUserUpFilesDir
End Select
End Function
'**************************************************
'函数名:ReturnChannelAllowUpFilesSize
'作 用:返回频道的最大允许上传文件大小
'参 数:ChannelID--频道ID
'**************************************************
Public Function ReturnChannelAllowUpFilesSize(ChannelID)
ChannelID = ChkClng(ChannelID)
Dim CRS:Set CRS=conn.execute("Select UpFilesSize From KS_Channel Where ChannelID=" & ChannelID)
If CInt(ChannelID) = 0 Or (CRS.EOF And CRS.BOF) Then
ReturnChannelAllowUpFilesSize = Setting(6)
Else
ReturnChannelAllowUpFilesSize = CRS(0)
End If
CRS.Close:Set CRS = Nothing
End Function
'**************************************************
'函数名:ReturnChannelAllowUpFilesType
'作 用:返回频道的允许上传的文件类型
'参 数:ChannelID--频道ID,TypeFlag 0-取全部 1-图片类型 2-flash 类型 3-Windows 媒体类型 4-Real 类型 5-其它类型
'**************************************************
Public Function ReturnChannelAllowUpFilesType(ChannelID, TypeFlag)
If ChkClng(ChannelID) = 0 Then ReturnChannelAllowUpFilesType = Setting(7):Exit Function
If Not IsNumeric(TypeFlag) Then TypeFlag = 0
If TypeFlag = 0 Then '所有允许的类型
ReturnChannelAllowUpFilesType = C_S(ChannelID,28) & "|" & C_S(ChannelID,29) & "|" & C_S(ChannelID,30) & "|" & C_S(ChannelID,31) & "|" & C_S(ChannelID,32)
Else
ReturnChannelAllowUpFilesType = C_S(ChannelID,27+TypeFlag)
End If
End Function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -