ASP文件上传核心代码

 

< ! --
=   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *  
*     作 者:  我本有心
=     QQ:      381584252
*      E - Mail: hztgcl1986@ 163 .com
=      转载请注明出处及作者!
*      版权所有,侵权必究!!!
=
*     http: // www.8848so.com,人物搜索,8848So    
=   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *   =   =   *  
-->
< %
' 此代码适合有一定ADODB.Stream基础的人阅读
'
这里只有服务器端代码,想必客户端不是问题所在

Dim  formsize,formdata,bincrlf,oencrlfplace,twocrlfplace,ext,filepath,p,l
Dim  usingstream,stream

formsize
= Request.TotalBytes
formdata
= Request.BinaryRead(formsize)

Set  usingstream = Server.CreateObject( " ADODB.Stream " )
usingstream.Type
= 1
usingstream.Open()
usingstream.Write(formdata)

bincrlf
= ChrB( 13 ) & ChrB( 10 ' 二进制回车换行
oencrlfplace = InStrB(formdata,bincrlf)  ' 44,第一次回车换行位置
twocrlfplace = InStrB(oencrlfplace + 1 ,formdata,bincrlf)  ' 第二次回车换行位置

Set  stream = Server.Createobject( " ADODB.Stream " )
stream.Type
= 1
stream.Open()
usingstream.Position
= oencrlfplace + 1
usingstream.CopyTo stream,twocrlfplace
- oencrlfplace - 3   ' 得到第二行数据,twocrlfplace-onecrlfplace-(回车换行长度+"长度)
stream.Position = 0
stream.Type
= 2   ' 字符串
stream.CharSet = " GB2312 "
streamtext
= stream.Readtext()  ' 读取第二行数据
stream.Close()

ext
= Mid (streamtext, InstrRev (streamtext, "" ) + 1 ' 得到文件名

filepath
= Server.MapPath( " upload/ " & ext)

p
= InStrB(formdata,bincrlf & bincrlf) + 4   ' 4为两次回车换行长度
l = InStrB(p + 1 ,formdata,LeftB(formdata,oencrlfplace - 1 )) - p - 2   ' 文件内容部分长度,onecrlfplace-1为第一行数据(也是分隔符),2为回车换行长度
stream.Type = 1
stream.Open()
usingstream.Position
= p - 1
usingstream.CopyTo stream,l 
' 文件内容数据
stream.SaveToFile filepath, 2   ' 保存文件

usingstream.Close():
Set  usingstream = Nothing
stream.Close():
Set  stream = Nothing
%
>

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值