您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> java >> 正文

风声无组件上传类2.1精简操作

作者:佚名    责任编辑:admin    更新时间:2022-06-22

class="area">

代码如下:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>进阶应用——风声无组件上传类</title>
<link href="../style/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

    <form action="upload.asp" enctype="multipart/form-data" name="form1" method="post">

产品图: <input name="strPhoto2" type="file" id="strPhoto2" />
          <input type="submit" name="Submit" value="上传" />
              <input type="reset" name="Submit2" value="重 置" />(大小&lt;500K)

    </form>

</body>
</html>

upload.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
’----------------------------------------------------------
’***************** 风声无组件上传类 2.1 *****************
’用法举例:进阶应用[添加产品二]
’该例主要说明手动保存模式更灵活的运用
’以常见的产品更新为例<br>
’该例以 gb2312(类默认,无须显示设置)字符集测试
’下面是上传程序(upload.asp)的代码和注释
’**********************************************************
’---------------------------------------------------------- 
OPTION EXPLICIT
Server.ScriptTimeOut=5000
%>
<!--include file="UpLoadClass.asp"-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>进阶应用——风声无组件上传类</title>
<link href="../style/default.css" rel="stylesheet" type="text/css" />
</head>

<body>
<%
dim request2 
’建立上传对象
set request2=New UpLoadClass

    ’设置为手动保存模式
    request2.AutoSave=2

    ’设置字符集,默认为 gb2312 字符集
    ’request2.Charset="UTF-8"


    ’设置服务器文件保存路径
    ’request2.SavePath="UpLoadFile/"

    request2.Open()


    ’设置产品大图最大为500K
    ’当然这里还可以设置不同的保存路径,限制格式
    request2.MaxSize=500*1024
    ’设置文件允许的附件类型 例如:gif/jpg/rar/zip
    request2.FileType="jpg/gif/bmp/png"

    
    ’如果保存图成功
    Response.Write("")
    if request2.Save("strPhoto2",0) then

        ’显示保存位置
        Response.Write("<p>产品图=&gt;"&request2.SavePath&request2.Form("strPhoto2")&"</p>")
    end if
    
    
    ’-------说明开始------
    ’如果是正确的jpg/gig/png/bmp图片格式文件,还可以获取图片宽高
    ’if request2.form("strPhoto2_Width")<>"" then
    ’Response.Write("图片宽:"&request2.form("strPhoto2_Width"))
    ’Response.Write("图片高:"&request2.form("strPhoto2_Height"))
    ’end if
    ’-------说明结束------
    
    ’Response.Write "<p>[<a href=""javascript:history.back();"">返回</a>]</p>"

    ’释放上传对象
    set request2=nothing
    %> 

</body>
</html>

<%
’----------------------------------------------------------
’*****************  风声无组件上传类 2.1  *****************
’作者:风声
’网站:http://www.fonshen.com
’邮件:[email protected]
’版权:版权全体,源代码公开,各种用途均可免费使用
’**********************************************************
’----------------------------------------------------------
Class UpLoadClass

    Private m_TotalSize,m_MaxSize,m_FileType,m_SavePath,m_AutoSave,m_Error,m_Charset
    Private m_dicForm,m_binForm,m_binItem,m_strDate,m_lngTime
    Public    FormItem,FileItem

    Public Property Get Version
        Version="Fonshen UpLoadClass Version 2.1"
    End Property

    Public Property Get Error
        Error=m_Error
    End Property

    Public Property Get Charset
        Charset=m_Charset
    End Property
    Public Property Let Charset(strCharset)
        m_Charset=strCharset
    End Property

    Public Property Get TotalSize
        TotalSize=m_TotalSize
    End Property
    Public Property Let TotalSize(lngSize)
        if isNumeric(lngSize) then m_TotalSize=Clng(lngSize)
    End Property

    Public Property Get MaxSize
        MaxSize=m_MaxSize
    End Property
    Public Property Let MaxSize(lngSize)
        if isNumeric(lngSize) then m_MaxSize=Clng(lngSize)
    End Property

    Public Property Get FileType
        FileType=m_FileType
    End Property
    Public Property Let FileType(strType)
        m_FileType=strType
    End Property

    Public Property Get SavePath
        SavePath=m_SavePath
    End Property
    Public Property Let SavePath(strPath)
        m_SavePath=Replace(strPath