采用艾恩asp上传的角本

最近因一个小开发的需求,进行了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,savpath
savepath = "files"
dim upload
dim title,xfileName

set upload = new AnUpLoad
upload.Exe = "*"
upload.MaxSize = 1024 * 1024 * 1024 '1G
upload.GetData()

title=upload.forms("title")
set xfile=upload.files("mfile")
if upload.ErrorID>0 then 
	response.Write upload.Description
else	
	if xfile.isfile then
		result = 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
    .Open
	end with 
xfineName=left(xfile.localname,InStr(xfile.localname,".")-1)
dim Ins
Ins="insert into demo(title,texp,tf,tddate) values('" & title  & "','" & xfineName & "','files\" & xfile.filename & "',getdate())"
Cn.execute Ins
'---------------------------------------------------------------------------------------------------	
	else
			response.Write xfile.Exception
		end if
	end if
end if
'-----------------------------------数据浏览---------------------------------------------------------
set Rd=server.createobject("adodb.recordset")
Rd.open "select row_number()over(order by id) as id ,title,texp,tddate,tf from demo ",cN
if 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.moveNext
wend
else
response.write "不好意思,目前没有在库的数据!!"
end if
Rd.close
cn.close
set Rd=nothing
set cN=nothing 
%>
</table>
再次感谢艾恩asp无组件上传所提供的帮助!!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值