UPLOAD.ASP代码

程序代码:
<!--#include file="UpLoad_Class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www. xml:lang="zh-cn" lang="zh-cn">
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<style type="text/css">
td,div,input,select,textarea,body {font-size:12px;}
body,form{margin:0px;padding:0;}
</style>
</head>
<body>
<%
'=====================================================================
' 文件名称:UpLoad.Asp
'=====================================================================
'------------------------------------------------------
Dim FormName,FormInput,oUpLoadType,oAction,oFileExe,ooFileSize,oFileSize,IsPicS,PicSp
'------------------------------------------------------
Response.Buffer = True
Response.ExpiresAbsolute = Now()-1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.Charset = "GB2312"
'------------------------------------------------------
FormName = Trim(Request("FormName"))
FormInput = Trim(Request("FormInput"))
oUpLoadType = Trim(Request("oUpLoadType"))
'------------------------------------------------------
Select Case oUpLoadType
    '------------------------------------------- oAspJpeg
    Case "oAspJpeg"
        oFileExe = "jpg|gif|swf|png"
        sFileSize = 540
    '-------------------------------------------
    Case Else
        oFileExe = "jpg|gif|swf|png"
        sFileSize = 888
End Select
oFileSize = 1024*sFileSize
'------------------------------------------------------
oAction = Trim(Request("oAction"))
Select Case oAction
    Case "UpLoadShow"
        Call UpLoadShow()
    Case "oUpLoad"
        Call oUpLoad()
    Case Else
        Call UpLoadShow()
End Select
'------------------------------------------------------
Sub UpLoadShow()
%>
<div style="text-align:center; margin:5px; padding:5px;">
<form name="upload" method="post" action="UpLoad.asp?oAction=oUpLoad&FormName=<%=FormName%>&FormInput=<%=FormInput%>" enctype="multipart/form-data">
  <table width="400" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#35867B">
    <tr>
      <td width="400" height="22" align="left" valign="middle" bgcolor="#35867B"> <strong>图片上传</strong>
      </td>
    </tr>
    <tr align="center" valign="middle">
      <td align="left" id="upid" height="80" width="400" bgcolor="#FFFFFF"> 选择文件:
        <input type="hidden" name="oUpLoadType" value="<%=oUpLoadType%>" /><input type="file" name="myUpLoad" />
      </td>
    </tr>
    <tr><td bgcolor="#FFFFFF">文件上传大小:<font color="blue"><%=BytesToString(oFileSize)%></font> 文件上传类型:<font color="red"><%=oFileExe%></font></td></tr>
    <tr align="center" valign="middle">
      <td height="24" width="400">
        <input type="submit" name="Submit" value="开始上传" class="button">
      </td>
    </tr>
  </table>
</form>
</div>
<%
End Sub
'------------------------------------------------------
Sub oUpLoad()
    Dim Upload,path,tempCls,fName,UpLoadFile
    '===============================================================================
    Set Upload = New AnUpLoad            '创建类实例
    Upload.SingleSize = oFileSize        '设置单个文件最大上传限制,按字节计;默认为不限制
    Upload.MaxSize = 1024*1024*1024        '设置最大上传限制,按字节计;默认为不限制
    Upload.Exe = oFileExe                '设置合法扩展名,以|分割,忽略大小写
    Upload.Charset = "gb2312"            '设置文本编码,默认为gb2312
    Upload.openProcesser = False        '禁止进度条功能,如果启用,需配合客户端程序
    Upload.GetData()                    '获取并保存数据,必须调用本方法
    '===============================================================================
    If Upload.ErrorID>0 Then                '判断错误号,如果myupload.Err<=0表示正常
        Response.Write Upload.Description    '如果出现错误,获取错误描述
    Else
        If Upload.files(-1).count > 0 Then    '这里判断你是否选择了文件
            oUpLoadType = Upload.Forms("oUpLoadType")
            Select Case oUpLoadType
                Case "oAspJpeg"
                    UpLoadFile = "../UpLoadFiles/"
                Case Else
                    UpLoadFile = "../UpLoadFiles/"
            End Select
            path = Server.MapPath(UpLoadFile)         '文件保存路径
            Set tempCls = Upload.files("myUpLoad")
            tempCls.SaveToFile path,0
            fName = tempCls.FileName
            Set tempCls = Nothing
            UpLoadFileName = UpLoadFile&fName
           
            If IsObjInstalled("Persits.Jpeg") Then
                S_UpLoadFileName = UpLoadFile&fName
                oS_Pic = StartJpeg(UpLoadFileName,S_UpLoadFileName)
                Call S_UpLoadOpener(FormName,"S_"&FormInput,oS_Pic)
                Call UpLoadOpener(FormName,FormInput,UpLoadFileName,"上传成功!")
            Else
                Call UpLoadOpener(FormName,FormInput,UpLoadFileName,"上传成功!")
            End If
        Else
            Call GoUpLoad("您没有上传任何文件!")
        End If
    End If
    Set Upload = Nothing
End Sub
'------------------------------------------------------
Sub UpLoadOpener(FName,FInput,FValue,OutStr)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("window.opener.document."&FName&"."&FInput&".value='"&FValue&"';")
    Echo("alert('"&OutStr&"');")
    Echo("window.opener =null;")
    Echo("window.close();")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub S_UpLoadOpener(FName,FInput,FValue)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("window.opener.document."&FName&"."&FInput&".value='"&FValue&"';")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub GoUpLoad(OutStr)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("alert('"&OutStr&"');")
    Echo("history.go(-1);")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub Echo(str)
    Response.Write(str) & vbcrlf
End Sub
'------------------------------------------------------
Function BytesToString(ByVal iSize)
    Dim sRet,KB,MB,S
    KB = 1024 : MB = KB * KB
    If Not IsNumeric(iSize) Then
        BytesToString = "未知"
        Exit Function
    End If
    If iSize < KB Then
        sRet = iSize & " Bytes"
    Else
        S = iSize / KB
        If S < 10 Then
            sRet = FormatNumber(iSize / KB, 2, -1) & " KB"
        ElseIf S < 100 Then
            sRet = FormatNumber(iSize / KB, 1, -1) & " KB"
        ElseIf S < 1000 Then
            sRet = FormatNumber(iSize / KB, 0, -1) & " KB"
        ElseIf S < 10000 Then
            sRet = FormatNumber(iSize / MB, 2, -1) & " MB"
        ElseIf S < 100000 Then
            sRet = FormatNumber(iSize / MB, 1, -1) & " MB"
        ElseIf S < 1000000 Then
            sRet = FormatNumber(iSize / MB, 0, -1) & " MB"
        ElseIf S < 10000000 Then
            sRet = FormatNumber(iSize / MB / KB, 2, -1) & " GB"
        Else
            sRet = FormatNumber(iSize / MB / KB, 1, -1) & " GB"
        End If
    End If
    BytesToString = sRet
End Function
Function IsObjInstalled(strClassString)
    On Error Resume Next
    IsObjInstalled = False
    Err = 0
    Dim xTestObj
    Set xTestObj = Server.CreateObject(strClassString)
    If 0 = Err Then IsObjInstalled = True
    Set xTestObj = Nothing
    Err = 0
End Function
Function StartJpeg(CodePic,IsCodePic)
    '================aspJpeg 开始====================
    If (CodePic = "" Or IsNull(CodePic)) Then
        Exit Function
    End If
    If JpegType <> 0 Then
       
        Set BG = Server.CreateObject("Persits.Jpeg")
        BG.Open Server.MapPath(CodePic)
        BG_W = BG.Width
        BG_H = BG.Height
       
        If JpegType = 1 Then
            BG.Canvas.Font.Color = "&H" & JpegColor
            BG.Canvas.Font.ShadowColor = &HFFFFFF
            BG.Canvas.Font.Family = JpegFont
            BG.Canvas.Font.Size = JpegSize
            BG.Canvas.Font.Bold = False
            BG.Canvas.Font.Quality = 3
            Select Case JpegLocation
                Case 0
                    x = 20 : y = 20
                Case 1
                    x = BG_W - Len(JpegTxt) * 15 : y = 20
                Case 2
                    x = 20 : y = BG_H - 20
                Case 3
                    x = BG_W - Len(JpegTxt) * 15 : y = BG_H - 20*2
                Case 4
                    x = BG_W\2 - Len(JpegTxt) * 15\2 : y = BG_H\2 - 20*2
            End Select
            BG.Canvas.PrintText x, y, JpegTxt
        End If
       
        If JpegType = 2 Then
            Set logo = Server.CreateObject("Persits.Jpeg")
            logo.Open Server.MapPath(JpegPic)
            logo_w = logo.Width
            logo_h = logo.Height
            Select Case JpegLocation
                Case 0
                    x = 20 : y = 20
                Case 1
                    x = BG_W - logo_w - 20 : y = 20
                Case 2
                    x = 20 : y = logo_h - 20
                Case 3
                    x = BG_W - logo_w - 20 : y = BG_H - logo_h - 20
                Case 4
                    x = BG_W\2 - logo_w\2 : y = BG_H\2 - logo_h - 20
            End Select
            BG.DrawImage x, y, logo, 0.8, &HFFFFFF
            Set logo = Nothing
        End If
       
        BG.Quality = 85
       
        BG.Save Server.MapPath(IsCodePic)
        Set BG = Nothing
        StartJpeg = IsCodePic
    End If
    '================aspJpeg 结束====================
End Function
%>
</body>
</html>