最好的图片水印实现思路(带演示-强烈要求faq)

时间:2023-02-19 19:20:38
大家先看一下水印产生后的演示效果,如果感觉演示效果不错然后再继续往下看。

演示地址: 最好的图片水印实现思路(带演示-强烈要求faq)

你能看到这句话,看样子你是认可了这个水印功能,呵呵,恭喜你,你可知道为了搞一个完美的水印效果我已经苦苦探索很多天了,如果不是为了提高信誉值我是绝对不会在此公布的,如果该帖还不能让我faq一下,那我只有撞墙了。

该组件整合了几个上传组件,你可以很方便的选择使用某种组件来上传
另外您还可以选择使用图片水印还是文字水印,等等还有好多东西等你来探索
具体都有注释说明,自己看吧,一共包含三个文件,下边我分别贴出这三个文件的源代码来

该组件完整版下载地址 http://7di.net/001.rar

upload.asp的代码
<!--#include FILE="Upload.inc"-->
<!-- #include File="class_upfile.asp" -->
<body>

<%
action = Trim(Request.QueryString("action"))
Select Case action
        Case "UploadFile"
                Call UploadFile()
        Case else
                Call Main()
End Select

Sub Main()
        Dim PostRanNum
        Randomize
        PostRanNum = Int(900*rnd)+1000
        Session("UploadCode") = Cstr(PostRanNum)
%>  <form name="myform" method="post" action="?action=UploadFile" enctype="multipart/form-data">
        <INPUT TYPE="hidden" NAME="UploadCode" value="<%=PostRanNum%>">
        <input type="file" name="uploadfile" id="strPhoto" size=35 ><input type="submit" name="Ok" value="上传图片或附件" class=input1> 
    </form><%
End Sub

'上传过程
Sub UploadFile()
        
        Server.ScriptTimeOut=9999999
        '-----------------------------------------------------------------------------
        upfiletype=replace("gif|jpg|png|bmp|rar|zip","|",",")

        FilePath="./"
        Set Upload = New UpFile_Cls
        
                Upload.UploadType                        = 0                                                                                        '设置上传组件类型 (0=无组件上传类,1=Aspupload3.0 ,2=SA-FileUp 4.0 ,3=DvFile.Upload V1.0)
                Upload.UploadPath                        = "./"                                                                                '设置上传路径
                Upload.MaxSize                                = 1000                                                                                '单位 KB
                Upload.InceptMaxFile                = 1                                                                                        '每次上传文件个数上限
                Upload.InceptFileType                = "gif,jpg,png,rar,zip,psd"                                        '设置上传文件限制
                Upload.RName                                = ""
                Upload.ChkSessionName                = "UploadCode"
                
                Upload.PreviewType                        = 1                                                                                        '设置预览图片组件类型

                Upload.PreviewImageWidth        = 130                                                                                '设置预览图片宽度
                Upload.PreviewImageHeight        = 100                                                                                '设置预览图片高度
                Upload.DrawImageWidth                = 114                                                                                '设置水印图片或文字区域宽度
                Upload.DrawImageHeight                = 36                                                                                '设置水印图片或文字区域高度
                Upload.DrawGraph                        = 0.7                                                                                '设置水印透明度
                Upload.DrawFontColor                = "#FF0000"                                                                        '设置水印文字颜色
                Upload.DrawFontFamily                = "Andale Mono"                                                                '设置水印文字字体格式
                Upload.DrawFontSize                        = 10                                                                                '设置水印文字字体大小
                Upload.DrawFontBold                        = 1                                                                                        '设置水印文字是否粗体
                Upload.DrawInfo                                = "a.jpg"                                                                        '设置水印文字信息或图片信息
                Upload.DrawType                                = 2                                                                                        '0=不加载水印 ,1=加载水印文字,2=加载水印图片
                Upload.DrawXYType                        = 4                                                                                        '"0" =左上,"1"=左下,"2"=居中,"3"=右上,"4"=右下
                Upload.DrawSizeType                        = 1                                                                                        '"0"=固定缩小,"1"=等比例缩小
                Upload.TransitionColor                = "#FFFFFF"                                                                        '透明度颜色设置

                '执行上传
                Upload.SaveUpFile

                If Upload.ErrCodes<>0 Then
                        Response.write "错误:"& Upload.Description & "[ <a href='upload.asp'>重新上传</a> ]"
                        Exit Sub
                End If
                If Upload.Count > 0 Then
                        For Each FormName In Upload.UploadFiles
                                Set File = Upload.UploadFiles(FormName)
                                F_FileName = FilePath & File.FileName
                                '创建预览及水印图片
                                If Upload.PreviewType<>999 and File.FileType=1 then
                                                F_Viewname =  FilePath&"pre" & Replace(File.FileName,File.FileExt,"") & "jpg"
                                                '创建预览图片:Call CreateView(原始文件的路径,预览文件名及路径,原文件后缀)
                                                Upload.CreateView F_FileName,F_Viewname,File.FileExt
                                End If
                                %><!-- <script>parent.myForm.Img.value+='<%=F_FileName%>'</script> --><%
                                Response.Write "文件地址:<a href="& F_FileName &">上传成功</a>![ <a href=upload.asp>再次上传</a> ]<font color=red>注意:请将此地址粘贴到下面图片地址框即可</font>"
                                Set File = Nothing
                        Next
                Else
                        Response.write "请正确选择要上传的文件。[ <a href='upload.asp'>重新上传</a> ]"
                        Exit Sub
                End If
        Set Upload = Nothing
End Sub

%>

24 个解决方案

#1



upload.inc的代码

<%
'----------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'*******************   无惧上传类 V1.0  ********************************
'作者:梁无惧
'***********************************************************************
'添加以下属性:
'InceptFileType 允许上传的文件类型,以英文逗号“,”分隔。
'添加以下方法:
'FileWidth                图片宽度
'FileHeight                图片高度
'***********************************************************************

Dim oUpFileStream

Class UpFile_Class
        Public Form,File,Version,Err
        Private CHK_FileType,CHK_MaxSize

        Private Sub Class_Initialize
                Version = "无惧上传类 Version V1.0"
                Err = -1
                CHK_FileType = ""
                CHK_MaxSize = -1
                Set Form = Server.CreateObject ("Scripting.Dictionary")
                Set File = Server.CreateObject ("Scripting.Dictionary")
                Set oUpFileStream = Server.CreateObject ("Adodb.Stream")
                Form.CompareMode = 1
                File.CompareMode = 1
                oUpFileStream.Type = 1
                oUpFileStream.Mode = 3
                oUpFileStream.Open
        End Sub

        Private Sub Class_Terminate  
                '清除变量及对像
                Form.RemoveAll
                Set Form = Nothing
                File.RemoveAll
                Set File = Nothing
                oUpFileStream.Close
                Set oUpFileStream = Nothing
        End Sub

        Public Property Get InceptFileType
                InceptFileType = CHK_FileType
        End Property
        Public Property Let InceptFileType(Byval vType)
                CHK_FileType = vType
        End Property

        Public Property Get MaxSize
                MaxSize = CHK_MaxSize
        End Property
        Public Property Let MaxSize(vSize)
                If IsNumeric(vSize) Then CHK_MaxSize = Int(vSize)
        End Property

        Public Sub GetDate()
           '定义变量
          Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoEnd,tStream,iStart,oFileInfo
          Dim sFormValue,sFileName,sFormName,RequestSize
          Dim iFindStart,iFindEnd,iFormStart,iFormEnd,FileBlag
           '代码开始
          RequestSize = Int(Request.TotalBytes)
          If  RequestSize < 1 Then
                Err = 1
                Exit Sub
          End If
          Set tStream = Server.CreateObject ("Adodb.Stream")
          oUpFileStream.Write Request.BinaryRead (RequestSize)
          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, "\"))
                        oFileInfo.FileExt = Lcase(Mid(sFileName,InStrRev(sFileName, ".")+1))
                        iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
                        iFindEnd = InStr (iFindStart,sInfo,vbCr)
                        oFileInfo.FileType = Ucase(Mid(sinfo,iFindStart,iFindEnd-iFindStart))
                        oFileInfo.FileStart = iInfoEnd
                        oFileInfo.FileSize = iFormStart -iInfoEnd -2
                        oFileInfo.FormName = sFormName
                        If Instr(oFileInfo.FileType,"IMAGE/") Or Instr(oFileInfo.FileType,"FLASH") Then
                                FileBlag = GetImageSize
                                oFileInfo.FileExt = FileBlag(0)
                                oFileInfo.FileWidth = FileBlag(1)
                                oFileInfo.FileHeight = FileBlag(2)
                                FileBlag = Empty
                        End If
                        If CHK_MaxSize > 0 Then
                                If oFileInfo.FileSize > CHK_MaxSize Then
                                        Err = 2
                                        Exit Sub
                                End If
                        End If
                        If CheckErr(oFileInfo.FileExt) = False Then
                                Exit Sub
                        End If
                        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
                tStream.Close
                iFormStart = iFormStart+iStart+2
          '如果到文件尾了就退出
          Loop Until  (iFormStart+2) = iFormEnd
          RequestBinDate = ""
          Set tStream = Nothing
        End Sub

#2



        '====================================================================
        '验证上传类型
        '====================================================================
        Private Function CheckErr(Byval ChkExt)
                CheckErr=False
                If CHK_FileType = "" Then CheckErr=True : Exit Function
                Dim ChkStr
                ChkStr = ","&Lcase(CHK_FileType)&","
                If Instr(ChkStr,","&ChkExt&",")>0 Then
                        CheckErr=True
                Else
                        Err = 3
                End If
        End Function
        '====================================================================
        '图像宽高类型读取
        '====================================================================
        Private Function Bin2Str(Byval Bin)
                Dim i, Str, Sclow
                For i = 1 To LenB(Bin)
                        Sclow = MidB(Bin,i,1)
                        If ASCB(Sclow)<128 Then
                                Str = Str & Chr(ASCB(Sclow))
                        Else
                                i = i+1
                                If i <= LenB(Bin) Then Str = Str & Chr(ASCW(MidB(Bin,i,1)&Sclow))
                        End If
                Next 
                Bin2Str = Str
        End Function

        Private Function Num2Str(Byval num,Byval Base,Byval Lens)
                Dim ImageSize
                ImageSize = ""
                While(num>=Base)
                        ImageSize = (num mod Base) & ImageSize
                        num = (num - num mod Base)/Base
                Wend
                Num2Str = Right(String(Lens,"0") & num & ImageSize,Lens)
        End Function

        Private Function Str2Num(Byval str,Byval Base)
                Dim ImageSize,i
                ImageSize = 0
                For i=1 To Len(str)
                        ImageSize = ImageSize *Base + Cint(Mid(str,i,1))
                Next
                Str2Num = ImageSize
        End Function

        Private Function BinVal(Byval bin)
                Dim ImageSize,i
                ImageSize = 0
                For i = lenb(bin) To 1 Step -1
                        ImageSize = ImageSize *256 + ASCB(Midb(bin,i,1))
                Next
                BinVal = ImageSize
        End Function

        Private Function BinVal2(Byval bin)
                Dim ImageSize,i
                ImageSize = 0
                For i = 1 To Lenb(bin)
                        ImageSize = ImageSize *256 + ASCB(Midb(bin,i,1))
                Next
                BinVal2 = ImageSize
        End Function

        Private Function GetImageSize() 
                Dim ImageSize(2),bFlag
                bFlag = oUpFileStream.Read(3)

                Select Case Hex(BinVal(bFlag))
                        Case "4E5089":
                                oUpFileStream.Read(15)
                                ImageSize(0) = "png"
                                ImageSize(1) = BinVal2(oUpFileStream.Read(2))
                                oUpFileStream.Read(2)
                                ImageSize(2) = BinVal2(oUpFileStream.Read(2))
                        Case "464947":
                                oUpFileStream.Read(3)
                                ImageSize(0) = "gif"
                                ImageSize(1) = BinVal(oUpFileStream.Read(2))
                                ImageSize(2) = BinVal(oUpFileStream.Read(2))
                        Case "535746":
                                Dim BinData,sConv,nBits
                                oUpFileStream.Read(5)
                                BinData = oUpFileStream.Read(1)
                                sConv = Num2Str(ASCB(BinData),2 ,8)
                                nBits = Str2Num(Left(sConv,5),2)
                                sConv = Mid(sConv,6)
                                While(Len(sConv)<nBits*4)
                                        BinData = oUpFileStream.Read(1)
                                        sConv = sConv&Num2Str(ASCB(BinData),2 ,8)
                                Wend
                                ImageSize(0) = "swf"
                                ImageSize(1) = Int(ABS(Str2Num(Mid(sConv,1*nBits+1,nBits),2)-Str2Num(Mid

(sConv,0*nBits+1,nBits),2))/20)
                                ImageSize(2) = Int(ABS(Str2Num(Mid(sConv,3*nBits+1,nBits),2)-Str2Num(Mid

(sConv,2*nBits+1,nBits),2))/20)
                        Case "535743":'flashmx
                                ImageSize(0) = "swf"
                                ImageSize(1) = 0
                                ImageSize(2) = 0
                        Case "FFD8FF":
                                Dim p1
                                Do 
                                        Do: p1 = BinVal(oUpFileStream.Read(1)): Loop While p1 = 255 And Not oUpFileStream.EOS
                                        If p1>191 and p1<196 Then Exit Do Else oUpFileStream.Read(BinVal2(oUpFileStream.Read

(2))-2)
                                        Do:p1 = BinVal(oUpFileStream.Read(1)):Loop While p1<255 And Not oUpFileStream.EOS
                                        Loop While True
                                        oUpFileStream.Read(3)
                                        ImageSize(0) = "jpg"
                                        ImageSize(2) = BinVal2(oUpFileStream.Read(2))
                                        ImageSize(1) = BinVal2(oUpFileStream.Read(2))
                        Case Else:
                                If Left(Bin2Str(bFlag),2) = "BM" Then
                                        oUpFileStream.Read(15)
                                        ImageSize(0) = "bmp"
                                        ImageSize(1) = BinVal(oUpFileStream.Read(4))
                                        ImageSize(2) = BinVal(oUpFileStream.Read(4))
                                Else
                                        ImageSize(0) = "(UNKNOWN)"
                                End If
                End Select
                GetImagesize = ImageSize
        End Function
End Class

'文件属性类
Class FileInfo_Class
        Public FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt,FileWidth,FileHeight
        Private Sub Class_Initialize
                FileWidth=0
                FileHeight=0
        End Sub
        '保存文件方法
        Public Sub SaveToFile (Byval Path)
                Dim Ext,oFileStream
                Ext = LCase(Mid(Path, InStrRev(Path, ".") + 1))
                If Ext <> FileExt Then Exit Sub
                If Trim(Path)="" or FileStart=0 or FileName="" or Right(Path,1)="/" Then Exit Sub
                'On Error Resume Next
                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 Sub
        '取得文件数据
        Public Function FileData
                oUpFileStream.Position = FileStart
                FileData = oUpFileStream.Read (FileSize)
        End Function
End Class
%>

#3


class_upfile.asp的代码

<%
'-----------------------------------------------------------------------
'--- 上传处理类模块
'-----------------------------------------------------------------------
'-- InceptFileType        : 设置上传类型属性 (以逗号分隔多个文件类型) String
'-- MaxSize                        : 设置上传文件大小上限 (单位:kb) Long
'-- InceptMaxFile        : 设置一次上传文件最大个数 Long
'-- UploadPath                : 设置保存的目录相对路径 String
'-- UploadType                : 设置上传组件类型 (0=无组件上传类,1=Aspupload3.0 ,2=SA-FileUp 4.0 ,3=DvFile.Upload V1.0)
'-- SaveUpFile                : 执行上传
'-- GetBinary                : 设置上传是否返回文件数据流  Bloon值 : True/False
'-- ChkSessionName        : 设置SESSION名,防止重复提交,SESSION名与提交的表单名要一致。
'-- RName设置文件名        : 定义文件名前缀 (如默认生成的文件名为200412230402587123.jpg
'                                                                        设置:RName="PRE_",生成的文件名为:PRE_200412230402587123.jpg)
'-----------------------------------------------------------------------
'-- 设置图片组件属性
'-- PreviewType                : 设置组件(0=CreatePreviewImage组件,1=AspJpegV1.2 ,2=SoftArtisans ImgWriter V1.21)
'-- PreviewImageWidth        : 设置预览图片宽度
'-- PreviewImageHeight        : 设置预览图片高度
'-- DrawImageWidth        : 设置水印图片或文字区域宽度
'-- DrawImageHeight        : 设置水印图片或文字区域高度
'-- DrawGraph                : 设置水印图片或文字区域透明度
'-- DrawFontColor        : 设置水印文字颜色
'-- DrawFontFamily        : 设置水印文字字体格式
'-- DrawFontSize        : 设置水印文字字体大小
'-- DrawFontBold        : 设置水印文字是否粗体
'-- DrawInfo                : 设置水印文字信息或图片信息
'-- DrawType                : 设置加载水印模式:0=不加载水印 ,1=加载水印文字 ,2=加载水印图片
'-- DrawXYType                : 图片添加水印LOGO位置坐标:"0" =左上,"1"=左下,"2"=居中,"3"=右上,"4"=右下
'-- DrawSizeType        : 生成预览图片大小规则:"0"=固定缩小,"1"=等比例缩小
'-----------------------------------------------------------------------
'-- 获取上传信息
'-- ObjName                        : 采用的组件名称
'-- Count                        : 上传文件总数
'-- CountSize                : 上传总大小字节数
'-- ErrCodes                : 错误NUMBER (默认为0)
'-- Description                : 错误描述
'-----------------------------------------------------------------------
'-- CreateView Imagename,TempFilename,FileExt
'        创建预览图片过程: 原始文件的相对路径,生成预览文件相对路径,原文件后缀
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'-- 获取文件对象属性 : UploadFiles
'-- FormName                : 表单名称
'-- FileName                : 生成的文件名称
'-- FilePath                : 保存文件的相对路径
'-- FileSize                : 文件大小
'-- FileContentType        : ContentType文件类型
'-- FileType                : 0=其它,1=图片,2=FLASH,3=音乐,4=电影
'-- FileData                : 文件数据流 (若组件不支持直接获取,则返回Null)
'-- FileExt                        : 文件后缀
'-- FileWidth                : 图片/Flash文件宽度        (其他文件默认=-1)
'-- FileHeight                : 图片/Flash文件高度        (其他文件默认=-1)
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'-- 获取表单对象属性 : UploadForms
'-- Count                        : 表单数
'-- key                                : 表单内容
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------

Class UpFile_Cls
        Private UploadObj,ImageObj
        Private FilePath,InceptFile,FileMaxSize,MaxFile,Upload_Type,FileInfo,IsBinary,SessionName
        Private Preview_Type,View_ImageWidth,View_ImageHeight,Draw_ImageWidth,Draw_ImageHeight,Draw_Graph
        Private Draw_FontColor,Draw_FontFamily,Draw_FontSize,Draw_FontBold,Draw_Info,Draw_Type,Draw_XYType,Draw_SizeType
        Private RName_Str,Transition_Color
        Public ErrCodes,ObjName,UploadFiles,UploadForms,Count,CountSize
        '-----------------------------------------------------------------------------------
        '初始化类
        '-----------------------------------------------------------------------------------
        Private Sub Class_Initialize
                SessionName = Empty
                IsBinary = False
                ErrCodes = 0
                Count = 0
                CountSize = 0
                FilePath = "./"
                InceptFile = ""
                FileMaxSize = -1
                MaxFile = 1
                Upload_Type = -1
                Preview_Type = 999
                ObjName = "未知组件"
                View_ImageWidth = 0
                View_ImageHeight = 0
                Draw_FontColor        = &H000000
                Draw_FontFamily        = "Arial"
                Draw_FontSize        = 10
                Draw_FontBold        = False
                Draw_Info                = "WWW.SZBLOGS.COM"
                Draw_Type                = -1
                Set UploadFiles = Server.CreateObject ("Scripting.Dictionary")
                Set UploadForms = Server.CreateObject ("Scripting.Dictionary")
                UploadFiles.CompareMode = 1
                UploadForms.CompareMode = 1
        End Sub

        '-----------------------------------------------------------------------------------
        '销毁类

#4


又见好东西,狂顶!!!

#5


支持.

#6


好东西。
试试好用不好用。

#7


mark

#8


支持,记号

#9


不错

#10


还以为是无组件的。。。
怎么压缩包里没包含组件文件啊?

#11


如果以前的话,faq还是基本上认可了.....8过现在不归偶们管...

#12


好东东

#13


感谢老少爷们们的支持

#14


上边的代码没有帖完,大家还是自己下载那个压缩包吧,那里有完整的代码

#15


跟动网的差不多麻

#16


收藏,楼主的精华。不明白,再来讨教!我正想用呢。
谢谢楼主!

#17


好东西呀!!!我喜欢,!!顶,不我要狂顶!

#18


拿动网的改的吧  谢谢楼主 我正需要呢 顶!!!

#19


辛苦辛苦!!!

#20


还是支持一下

#21


mark

#22


啥是FAQ?

#23


mark

#24


mark

#1



upload.inc的代码

<%
'----------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'*******************   无惧上传类 V1.0  ********************************
'作者:梁无惧
'***********************************************************************
'添加以下属性:
'InceptFileType 允许上传的文件类型,以英文逗号“,”分隔。
'添加以下方法:
'FileWidth                图片宽度
'FileHeight                图片高度
'***********************************************************************

Dim oUpFileStream

Class UpFile_Class
        Public Form,File,Version,Err
        Private CHK_FileType,CHK_MaxSize

        Private Sub Class_Initialize
                Version = "无惧上传类 Version V1.0"
                Err = -1
                CHK_FileType = ""
                CHK_MaxSize = -1
                Set Form = Server.CreateObject ("Scripting.Dictionary")
                Set File = Server.CreateObject ("Scripting.Dictionary")
                Set oUpFileStream = Server.CreateObject ("Adodb.Stream")
                Form.CompareMode = 1
                File.CompareMode = 1
                oUpFileStream.Type = 1
                oUpFileStream.Mode = 3
                oUpFileStream.Open
        End Sub

        Private Sub Class_Terminate  
                '清除变量及对像
                Form.RemoveAll
                Set Form = Nothing
                File.RemoveAll
                Set File = Nothing
                oUpFileStream.Close
                Set oUpFileStream = Nothing
        End Sub

        Public Property Get InceptFileType
                InceptFileType = CHK_FileType
        End Property
        Public Property Let InceptFileType(Byval vType)
                CHK_FileType = vType
        End Property

        Public Property Get MaxSize
                MaxSize = CHK_MaxSize
        End Property
        Public Property Let MaxSize(vSize)
                If IsNumeric(vSize) Then CHK_MaxSize = Int(vSize)
        End Property

        Public Sub GetDate()
           '定义变量
          Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoEnd,tStream,iStart,oFileInfo
          Dim sFormValue,sFileName,sFormName,RequestSize
          Dim iFindStart,iFindEnd,iFormStart,iFormEnd,FileBlag
           '代码开始
          RequestSize = Int(Request.TotalBytes)
          If  RequestSize < 1 Then
                Err = 1
                Exit Sub
          End If
          Set tStream = Server.CreateObject ("Adodb.Stream")
          oUpFileStream.Write Request.BinaryRead (RequestSize)
          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, "\"))
                        oFileInfo.FileExt = Lcase(Mid(sFileName,InStrRev(sFileName, ".")+1))
                        iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
                        iFindEnd = InStr (iFindStart,sInfo,vbCr)
                        oFileInfo.FileType = Ucase(Mid(sinfo,iFindStart,iFindEnd-iFindStart))
                        oFileInfo.FileStart = iInfoEnd
                        oFileInfo.FileSize = iFormStart -iInfoEnd -2
                        oFileInfo.FormName = sFormName
                        If Instr(oFileInfo.FileType,"IMAGE/") Or Instr(oFileInfo.FileType,"FLASH") Then
                                FileBlag = GetImageSize
                                oFileInfo.FileExt = FileBlag(0)
                                oFileInfo.FileWidth = FileBlag(1)
                                oFileInfo.FileHeight = FileBlag(2)
                                FileBlag = Empty
                        End If
                        If CHK_MaxSize > 0 Then
                                If oFileInfo.FileSize > CHK_MaxSize Then
                                        Err = 2
                                        Exit Sub
                                End If
                        End If
                        If CheckErr(oFileInfo.FileExt) = False Then
                                Exit Sub
                        End If
                        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
                tStream.Close
                iFormStart = iFormStart+iStart+2
          '如果到文件尾了就退出
          Loop Until  (iFormStart+2) = iFormEnd
          RequestBinDate = ""
          Set tStream = Nothing
        End Sub

#2



        '====================================================================
        '验证上传类型
        '====================================================================
        Private Function CheckErr(Byval ChkExt)
                CheckErr=False
                If CHK_FileType = "" Then CheckErr=True : Exit Function
                Dim ChkStr
                ChkStr = ","&Lcase(CHK_FileType)&","
                If Instr(ChkStr,","&ChkExt&",")>0 Then
                        CheckErr=True
                Else
                        Err = 3
                End If
        End Function
        '====================================================================
        '图像宽高类型读取
        '====================================================================
        Private Function Bin2Str(Byval Bin)
                Dim i, Str, Sclow
                For i = 1 To LenB(Bin)
                        Sclow = MidB(Bin,i,1)
                        If ASCB(Sclow)<128 Then
                                Str = Str & Chr(ASCB(Sclow))
                        Else
                                i = i+1
                                If i <= LenB(Bin) Then Str = Str & Chr(ASCW(MidB(Bin,i,1)&Sclow))
                        End If
                Next 
                Bin2Str = Str
        End Function

        Private Function Num2Str(Byval num,Byval Base,Byval Lens)
                Dim ImageSize
                ImageSize = ""
                While(num>=Base)
                        ImageSize = (num mod Base) & ImageSize
                        num = (num - num mod Base)/Base
                Wend
                Num2Str = Right(String(Lens,"0") & num & ImageSize,Lens)
        End Function

        Private Function Str2Num(Byval str,Byval Base)
                Dim ImageSize,i
                ImageSize = 0
                For i=1 To Len(str)
                        ImageSize = ImageSize *Base + Cint(Mid(str,i,1))
                Next
                Str2Num = ImageSize
        End Function

        Private Function BinVal(Byval bin)
                Dim ImageSize,i
                ImageSize = 0
                For i = lenb(bin) To 1 Step -1
                        ImageSize = ImageSize *256 + ASCB(Midb(bin,i,1))
                Next
                BinVal = ImageSize
        End Function

        Private Function BinVal2(Byval bin)
                Dim ImageSize,i
                ImageSize = 0
                For i = 1 To Lenb(bin)
                        ImageSize = ImageSize *256 + ASCB(Midb(bin,i,1))
                Next
                BinVal2 = ImageSize
        End Function

        Private Function GetImageSize() 
                Dim ImageSize(2),bFlag
                bFlag = oUpFileStream.Read(3)

                Select Case Hex(BinVal(bFlag))
                        Case "4E5089":
                                oUpFileStream.Read(15)
                                ImageSize(0) = "png"
                                ImageSize(1) = BinVal2(oUpFileStream.Read(2))
                                oUpFileStream.Read(2)
                                ImageSize(2) = BinVal2(oUpFileStream.Read(2))
                        Case "464947":
                                oUpFileStream.Read(3)
                                ImageSize(0) = "gif"
                                ImageSize(1) = BinVal(oUpFileStream.Read(2))
                                ImageSize(2) = BinVal(oUpFileStream.Read(2))
                        Case "535746":
                                Dim BinData,sConv,nBits
                                oUpFileStream.Read(5)
                                BinData = oUpFileStream.Read(1)
                                sConv = Num2Str(ASCB(BinData),2 ,8)
                                nBits = Str2Num(Left(sConv,5),2)
                                sConv = Mid(sConv,6)
                                While(Len(sConv)<nBits*4)
                                        BinData = oUpFileStream.Read(1)
                                        sConv = sConv&Num2Str(ASCB(BinData),2 ,8)
                                Wend
                                ImageSize(0) = "swf"
                                ImageSize(1) = Int(ABS(Str2Num(Mid(sConv,1*nBits+1,nBits),2)-Str2Num(Mid

(sConv,0*nBits+1,nBits),2))/20)
                                ImageSize(2) = Int(ABS(Str2Num(Mid(sConv,3*nBits+1,nBits),2)-Str2Num(Mid

(sConv,2*nBits+1,nBits),2))/20)
                        Case "535743":'flashmx
                                ImageSize(0) = "swf"
                                ImageSize(1) = 0
                                ImageSize(2) = 0
                        Case "FFD8FF":
                                Dim p1
                                Do 
                                        Do: p1 = BinVal(oUpFileStream.Read(1)): Loop While p1 = 255 And Not oUpFileStream.EOS
                                        If p1>191 and p1<196 Then Exit Do Else oUpFileStream.Read(BinVal2(oUpFileStream.Read

(2))-2)
                                        Do:p1 = BinVal(oUpFileStream.Read(1)):Loop While p1<255 And Not oUpFileStream.EOS
                                        Loop While True
                                        oUpFileStream.Read(3)
                                        ImageSize(0) = "jpg"
                                        ImageSize(2) = BinVal2(oUpFileStream.Read(2))
                                        ImageSize(1) = BinVal2(oUpFileStream.Read(2))
                        Case Else:
                                If Left(Bin2Str(bFlag),2) = "BM" Then
                                        oUpFileStream.Read(15)
                                        ImageSize(0) = "bmp"
                                        ImageSize(1) = BinVal(oUpFileStream.Read(4))
                                        ImageSize(2) = BinVal(oUpFileStream.Read(4))
                                Else
                                        ImageSize(0) = "(UNKNOWN)"
                                End If
                End Select
                GetImagesize = ImageSize
        End Function
End Class

'文件属性类
Class FileInfo_Class
        Public FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt,FileWidth,FileHeight
        Private Sub Class_Initialize
                FileWidth=0
                FileHeight=0
        End Sub
        '保存文件方法
        Public Sub SaveToFile (Byval Path)
                Dim Ext,oFileStream
                Ext = LCase(Mid(Path, InStrRev(Path, ".") + 1))
                If Ext <> FileExt Then Exit Sub
                If Trim(Path)="" or FileStart=0 or FileName="" or Right(Path,1)="/" Then Exit Sub
                'On Error Resume Next
                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 Sub
        '取得文件数据
        Public Function FileData
                oUpFileStream.Position = FileStart
                FileData = oUpFileStream.Read (FileSize)
        End Function
End Class
%>

#3


class_upfile.asp的代码

<%
'-----------------------------------------------------------------------
'--- 上传处理类模块
'-----------------------------------------------------------------------
'-- InceptFileType        : 设置上传类型属性 (以逗号分隔多个文件类型) String
'-- MaxSize                        : 设置上传文件大小上限 (单位:kb) Long
'-- InceptMaxFile        : 设置一次上传文件最大个数 Long
'-- UploadPath                : 设置保存的目录相对路径 String
'-- UploadType                : 设置上传组件类型 (0=无组件上传类,1=Aspupload3.0 ,2=SA-FileUp 4.0 ,3=DvFile.Upload V1.0)
'-- SaveUpFile                : 执行上传
'-- GetBinary                : 设置上传是否返回文件数据流  Bloon值 : True/False
'-- ChkSessionName        : 设置SESSION名,防止重复提交,SESSION名与提交的表单名要一致。
'-- RName设置文件名        : 定义文件名前缀 (如默认生成的文件名为200412230402587123.jpg
'                                                                        设置:RName="PRE_",生成的文件名为:PRE_200412230402587123.jpg)
'-----------------------------------------------------------------------
'-- 设置图片组件属性
'-- PreviewType                : 设置组件(0=CreatePreviewImage组件,1=AspJpegV1.2 ,2=SoftArtisans ImgWriter V1.21)
'-- PreviewImageWidth        : 设置预览图片宽度
'-- PreviewImageHeight        : 设置预览图片高度
'-- DrawImageWidth        : 设置水印图片或文字区域宽度
'-- DrawImageHeight        : 设置水印图片或文字区域高度
'-- DrawGraph                : 设置水印图片或文字区域透明度
'-- DrawFontColor        : 设置水印文字颜色
'-- DrawFontFamily        : 设置水印文字字体格式
'-- DrawFontSize        : 设置水印文字字体大小
'-- DrawFontBold        : 设置水印文字是否粗体
'-- DrawInfo                : 设置水印文字信息或图片信息
'-- DrawType                : 设置加载水印模式:0=不加载水印 ,1=加载水印文字 ,2=加载水印图片
'-- DrawXYType                : 图片添加水印LOGO位置坐标:"0" =左上,"1"=左下,"2"=居中,"3"=右上,"4"=右下
'-- DrawSizeType        : 生成预览图片大小规则:"0"=固定缩小,"1"=等比例缩小
'-----------------------------------------------------------------------
'-- 获取上传信息
'-- ObjName                        : 采用的组件名称
'-- Count                        : 上传文件总数
'-- CountSize                : 上传总大小字节数
'-- ErrCodes                : 错误NUMBER (默认为0)
'-- Description                : 错误描述
'-----------------------------------------------------------------------
'-- CreateView Imagename,TempFilename,FileExt
'        创建预览图片过程: 原始文件的相对路径,生成预览文件相对路径,原文件后缀
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'-- 获取文件对象属性 : UploadFiles
'-- FormName                : 表单名称
'-- FileName                : 生成的文件名称
'-- FilePath                : 保存文件的相对路径
'-- FileSize                : 文件大小
'-- FileContentType        : ContentType文件类型
'-- FileType                : 0=其它,1=图片,2=FLASH,3=音乐,4=电影
'-- FileData                : 文件数据流 (若组件不支持直接获取,则返回Null)
'-- FileExt                        : 文件后缀
'-- FileWidth                : 图片/Flash文件宽度        (其他文件默认=-1)
'-- FileHeight                : 图片/Flash文件高度        (其他文件默认=-1)
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'-- 获取表单对象属性 : UploadForms
'-- Count                        : 表单数
'-- key                                : 表单内容
'-----------------------------------------------------------------------
'-----------------------------------------------------------------------

Class UpFile_Cls
        Private UploadObj,ImageObj
        Private FilePath,InceptFile,FileMaxSize,MaxFile,Upload_Type,FileInfo,IsBinary,SessionName
        Private Preview_Type,View_ImageWidth,View_ImageHeight,Draw_ImageWidth,Draw_ImageHeight,Draw_Graph
        Private Draw_FontColor,Draw_FontFamily,Draw_FontSize,Draw_FontBold,Draw_Info,Draw_Type,Draw_XYType,Draw_SizeType
        Private RName_Str,Transition_Color
        Public ErrCodes,ObjName,UploadFiles,UploadForms,Count,CountSize
        '-----------------------------------------------------------------------------------
        '初始化类
        '-----------------------------------------------------------------------------------
        Private Sub Class_Initialize
                SessionName = Empty
                IsBinary = False
                ErrCodes = 0
                Count = 0
                CountSize = 0
                FilePath = "./"
                InceptFile = ""
                FileMaxSize = -1
                MaxFile = 1
                Upload_Type = -1
                Preview_Type = 999
                ObjName = "未知组件"
                View_ImageWidth = 0
                View_ImageHeight = 0
                Draw_FontColor        = &H000000
                Draw_FontFamily        = "Arial"
                Draw_FontSize        = 10
                Draw_FontBold        = False
                Draw_Info                = "WWW.SZBLOGS.COM"
                Draw_Type                = -1
                Set UploadFiles = Server.CreateObject ("Scripting.Dictionary")
                Set UploadForms = Server.CreateObject ("Scripting.Dictionary")
                UploadFiles.CompareMode = 1
                UploadForms.CompareMode = 1
        End Sub

        '-----------------------------------------------------------------------------------
        '销毁类

#4


又见好东西,狂顶!!!

#5


支持.

#6


好东西。
试试好用不好用。

#7


mark

#8


支持,记号

#9


不错

#10


还以为是无组件的。。。
怎么压缩包里没包含组件文件啊?

#11


如果以前的话,faq还是基本上认可了.....8过现在不归偶们管...

#12


好东东

#13


感谢老少爷们们的支持

#14


上边的代码没有帖完,大家还是自己下载那个压缩包吧,那里有完整的代码

#15


跟动网的差不多麻

#16


收藏,楼主的精华。不明白,再来讨教!我正想用呢。
谢谢楼主!

#17


好东西呀!!!我喜欢,!!顶,不我要狂顶!

#18


拿动网的改的吧  谢谢楼主 我正需要呢 顶!!!

#19


辛苦辛苦!!!

#20


还是支持一下

#21


mark

#22


啥是FAQ?

#23


mark

#24


mark