采用艾恩asp上传的角本

来源:互联网 发布:软件进口关税税率 编辑:程序博客网 时间:2024/05/24 03:43

最近因一个小开发的需求,进行了Asp的文件上,在网上也看了不少的文章,多数都是将文件写入与文件上分开,另一方面就是写的不是很明确。而最终,我采用了艾恩asp上传的角本。这一点非常感谢艾恩的大力贡献,有需要的朋友,可以如下联系:

'=========================================================
 'Class: AnUpLoad
 'Author: Anlige
 'Version:AienAspUpload V13.12.09
 'CreationDate: 2008-04-12
 'ModificationDate: 2013-12-09
 'Homepage: http://dev.mo.cn
 'Email: zhanghuiguoanlige@126.com
 'QQ: 1034555083
'=========================================================

网上有特别多的类子,很多的时候,大家在引用的时候,最大的问题就是一会儿好,一会儿又不能用了,其实最关键的问题在于编码的格式。采用艾恩asp的文本从上传页面到上传的后台角本都必须采用gb2312的格式,特别是引用是利用统一的数据库连接的asp页面时,一般大家都会采用Uft-8,而这个问题也会产生报错。

以下是个小Demo,以便以后使用和对有用的朋友分享

上传界面如下:

代码:

<html><head></head><body><style>.w{width:300px;}</style><form action="p11.asp" method="post" enctype="multipart/form-data"><table><tr><th colspan="2" align="center">上传Demo</th></tr><tr><td align="center">文章标题</td><td><input type="text" name="title" class="w" value="" /></td></tr><tr><td align="center">上传文件</td><td><input type="file" name="mFile" class="w"/></td></tr><tr align="center"><td colspan="2"><input type="submit" value="登记" /></td></tr></table></form></body></html>

存储与浏览的部分

界面:

代码:

<!--#include file="script/UpLoad_Class.asp"--><%dim xfile,savpathsavepath = "files"dim uploaddim title,xfileNameset upload = new AnUpLoadupload.Exe = "*"upload.MaxSize = 1024 * 1024 * 1024 '1Gupload.GetData()title=upload.forms("title")set xfile=upload.files("mfile")if upload.ErrorID>0 then response.Write upload.Descriptionelseif xfile.isfile thenresult = xfile.saveToFile(savepath,0,true)if result then'-----------------------------------写入数据库-------------------------------------------------------set cN=server.createobject("adodb.connection")with Cn    .Provider = "sqloledb"      ' Set SQLOLEDB connection properties.    .Properties("Data Source").Value = "localhost"    .Properties("Initial Catalog").Value = "web"    .Properties("User ID").Value = "sa"    .Properties("Password").Value = 1    .Openend with xfineName=left(xfile.localname,InStr(xfile.localname,".")-1)dim InsIns="insert into demo(title,texp,tf,tddate) values('" & title  & "','" & xfineName & "','files\" & xfile.filename & "',getdate())"Cn.execute Ins'---------------------------------------------------------------------------------------------------elseresponse.Write xfile.Exceptionend ifend ifend if'-----------------------------------数据浏览---------------------------------------------------------set Rd=server.createobject("adodb.recordset")Rd.open "select row_number()over(order by id) as id ,title,texp,tddate,tf from demo ",cNif not Rd.eof and not Rd.bof then%><table border="1" align="center"><tr><th colspan=4>上传数据Demo</th></tr><tr><th>序号</th><th>主题</th><th>文件名</th><th>上传日期</th></tr><%while not Rd.eof %><tr><td><%=Rd(0)%></td><td><%=Rd(1)%></td><td><a href=<%=rd(4)%>><%=rd(2)%></a></td><td><%=rd(2)%></td></tr><%Rd.moveNextwendelseresponse.write "不好意思,目前没有在库的数据!!"end ifRd.closecn.closeset Rd=nothingset cN=nothing %></table>
再次感谢艾恩asp无组件上传所提供的帮助!!


0 0
原创粉丝点击