当前位置:首页 » 文件管理 » asp上传

asp上传

发布时间: 2022-01-08 21:09:19

1. 【ASP上传程序】

依我说 还是用别人做好的类就行了 没必要搞的那么明白 你只要会用遥控器就可以了 不需要知道电视的构造 风声无组件上传类 还不错
如果你确定想知道电视是怎么造的 那就把文件发到我邮箱里吧 当然 我也只是帮你参考参考 不一定能解决你的问题 还望谅解 邮箱 [email protected]

2. asp 上传

我们用来获取上一个页面传递过来的数据一般是使用Request对象。同样的,我们也可以使用Request对象来获取上传上来的文件数据,使用的方法是Request.BinaryRead()。而我们要从数据库中读出来图片的数据显示到网页上面要用到的方法是:

Request.BinaryWrite()。在我们得到了图片的数据,要保存到数据库中的时候,不可以直接使用Insert语句对数据库进行操作,而是要使用ADO的AppendChunk方法,同样的,读出数据库中的图片数据,要使用GetChunk方法。各个方法的具体语法如下:

* Request.BinaryRead语法:

variant = Request.BinaryRead(count)
参数

variant

返回值保存着从客户端读取到数据。

count

指明要从客户端读取的数据量大小,这个值小于或者等于使用方法

Request.TotalBytes得到的数据量。

* Request.BinaryWrite语法:

Request.BinaryWrite data

参数

data

要写入到客户端浏览器中的数据包。

* Request.TotalBytes语法:

variant = Request.TotalBytes

参数

variant

返回从客户端读取到数据量的字节数。

* AppendChunk语法

将数据追加到大型文本、二进制数据 Field 或 Parameter 对象。

object.AppendChunk Data

参数

object Field 或 Parameter 对象

Data 变体型,包含追加到对象中的数据。

说明

使用 Field 或 Parameter 对象的 AppendChunk 方法可将长二进制或字符数据填写到对象中。在系统内存有限的情况下,可以使用 AppendChunk 方法对长整型值进行部分而非全部的操作。

* GetChunk语法

返回大型文本或二进制数据 Field 对象的全部或部分内容 。

variable = field.GetChunk( Size )

返回值

返回变体型。

参数

Size 长整型表达式,等于所要检索的字节或字符数。

说明

使用 Field 对象的 GetChunk 方法检索其部分或全部长二进制或字符数据。在系统内存有限的情况下,可使用 GetChunk 方法处理部分而非全部的长整型值。

GetChunk 调用返回的数据将赋给“变量”。如果 Size 大于剩余的数据,则

GetChunk 仅返回剩余的数据而无需用空白填充“变量”。如果字段为空,则

GetChunk 方法返回 Null。

每个后续的 GetChunk 调用将检索从前一次 GetChunk 调用停止处开始的数据。但是,如果从一个字段检索数据然后在当前记录中设置或读取另一个字段的值,ADO 将认为已从第一个字段中检索出数据。如果在第一个字段上再次调用 GetChunk 方法,ADO 将把调用解释为新的 GetChunk 操作并从记录的起始处开始读取。如果其他 Recordset 对象不是首个 Recordset 对象的副本,则访问其中的字段不会破坏 GetChunk 操作。如果 Field 对象的 Attributes 属性中的 adFldLong 位设置为 True,则可以对该字段使用 GetChunk 方法。如果在 Field 对象上使用 Getchunk 方法时没有当前记录,将产生错误 3021(无当前记录)。

3. ASP网页上传

比如你的数据库mydata.mdb放在data文件夹里面,conn文件路径可以这么写:
Const SiteDb = "/Data/mydata.mdb"

发个完整的给你参考下:
<%

function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")
fString = Replace(fString, CHR(32), "")
fString = Replace(fString, CHR(9), "")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), " ")
fString = Replace(fString, CHR(10), " ")
fString=ChkBadWords(fString)
HTMLEncode = fString
end if
end function

function checkStr(str)
if isnull(str) then
checkStr = ""
exit function
end if
checkStr=replace(str,"'","''")
end function
Const SiteDb = "/Data/mydata.mdb"

dim sessionvar
Dim ConnStr
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(MyDbPath & SiteDb)
on error resume next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
sessionvar="admin&^jffsddasf"
%>

4. asp上传的代码怎么写

据我所知,上传的对象有两种,adodb.stream和fso。。。
我想问的是一个最简单的上传代码是怎样?请问大家能给我一个adodb.stream和fso的例子吗?
因为我在网上搜索的代码都是长篇大论。。。因为小弟是初学者,所以不明白。。。。
上传文件的代码需要这么长吗?

5. asp上传程序

这个程序是没有任何漏洞的,要想使用得更好,在上传时和执行文件都加上权限那就更安全了,不明白留言给我!

本程序分三个页面及一个文件夹(UpLoadFile),具体文件代码如下:

文件一:上传文件页面

<table width="670" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#999999">
<form action="upload.asp" enctype="multipart/form-data" name="form1" method="post">
<tr bgcolor="#999999">
<td width="180"><font color="#FFFFFF">项目</font></td>
<td align="center"><font color="#FFFFFF">内容</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="180">产品名称</td>
<td>
<input name="strName" type="text" id="strName"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="180">产品图片</td>
<td>
<input name="strPhoto" type="file" id="strPhoto"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="180">图片格式:gif/jpg<br>
图片大小:150K <br>
产品介绍</td>
<td>
<input name="strRemark" cols="45" rows="6" id="strRemark"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="180"> </td>
<td>
<input type="submit" name="Submit" value="提 交">
<input type="reset" name="Submit2" value="重 置"></td>
</tr>
</form>
</table>

文件二:上传执行数据页面

<%
OPTION EXPLICIT
Server.ScriptTimeOut=5000
%>
<!--#include FILE="UpLoadClass.asp"-->
<%
dim request2

'建立上传对象
set request2=New UpLoadClass

'以默认设置打开上传对象
'建议直接修改类的63,64,65,66行为自己需要的默认设置
'类的初始默认值分别为
'p_MaxSize = 153600 单文件最大150K
'p_FileType = "jpg/gif" 允许上传jpg/gif格式文件
'p_SavePath = "" 在当前目录保存文件,这里是相对路径,如:“UpLoadFile/”
'p_AutoSave = 0 自动生成无重复文件名保存目标文件
'这样每次就不要设置同样的参数了
request2.open()
%>
<html>
<head>
<title>快速应用——风声无组件上传类</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="basic.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="760" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" style="border:1px solid #999999">
<tr>
<td><blockquote>
<%
'显示类版本
response.Write("<br>"&request2.version&"<br>")

'显示产品名称
response.Write("<br>产品名称:"&request2.Form("strName"))

'显示源文件路径与名称
response.Write("<br>产品图片:"&request2.Form("strPhoto_Path")&request2.Form("strPhoto_Name"))
response.Write("=>")

'显示目标文件路径与名称
response.Write(request2.SavePath&request2.Form("strPhoto"))

'显示产品介绍
response.Write("<br>产品介绍:"&request2.Form("strRemark"))

'-------说明开始------
'可以看出上面的显示是淋漓尽致的
'文件是否需要保存由类自动判断,这已经符合大多数情况下的应用
'如果您需要更灵活的处理,参见[进阶应用]
'-------说明结束------

response.write "<br>[<a href=""javascript:history.back();"">返回</a>]"
%>
</blockquote></td>
</tr>
</table>
</body>
</html>
<%
'释放上传对象
set request2=nothing
%>

文件三:上传定义文件

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

Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem

Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property

Public Property Get Error
Error=p_Error
End Property

Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End Property

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

Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property

Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property

Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 1536000 '单个文件大小1.5M
p_FileType = "" '可上传任意类型文件,jpg/gif/swf
p_SavePath = "UpLoadFile/" '保存文件路径
p_AutoSave = 1 '用原名保存图片,0为用时间
strDate = replace(cstr(Date()),"-","")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub

Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End Sub

Public Sub Open()
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData

Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)

intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)

Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()

p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz

intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)

if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if

binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub

Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function

Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function

Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function

Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binFormStream.Read(objForm(Item&"_Size"))
end if
End Function

Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function

Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function

Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function

End Class
%>

6. ASP上传代码

Asp无组件生成缩略图

网上有不少生成缩略图的ASP组件。若你的虚拟空间不支持注册新组件,可能会感觉自己的网站失色不少。心晴不才,结合网上资源写了个无组件生成缩略图程序,仅供参考。

还是先看看基础部分吧。首先,我们知道在页面中显示图片是如下代码:

<img src="pic.gif" border="0" width="300" height="260">

src是图片路径,border控制图片边缘宽度,width是图片的长度,height是图片的高度。缩略图的生成其实就是在原始尺寸上缩放。但一般为了尽量少失真,我们都会按比例缩放。于是,获取图片的长宽尺寸也就成了生成缩略图的重点。

下面便是编写无组件生成缩略图的步骤:

1.无组件获取图片大小

以前刚学ASP不久时看到过一篇利用ASCII码实现无组件获取图片尺寸的文章。后来试了试,发现在获取jpg类图片尺寸时总是不能正确显示,在网上查了查,居然有不少网站转载这个程序,但没有一家指出此程序的缺陷,也就更谈不上解决缺陷的办法了。后来又google了一下,终于找到了一篇介绍利用ADODB.stream获取图片尺寸的文章,按其介绍的方法,修改里面的代码试了试,效果真的还不错,现在将其拿出来与大家分享:

利用ADODB.stream获取图片尺寸的通用类

<%
'//////////// GPS:Get Picture Size //////////////
'//////////////利用ADODB.stream获取图片尺寸//////////////
'/////////Cited By Leon(心晴) 2005年8月11日//////////

Class GPS
Dim aso

Private Sub Class_Initialize
Set aso=CreateObject("Adodb.Stream")
aso.Mode=3
aso.Type=1
aso.Open
End Sub

Private Sub Class_Terminate
set aso=nothing
End Sub

Private Function Bin2Str(Bin)
Dim I, Str
For I=1 to LenB(Bin)
clow=MidB(Bin,I,1)
if AscB(clow)<128 then
Str = Str & Chr(ASCB(clow))
Else
I=I+1
if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow))
end If
Next
Bin2Str = Str
End Function

Private Function Num2Str(num,base,lens)
'GPS (2005-8-11)
dim ret
ret = ""
while(num>=base)
ret = (num mod base) & ret
num = (num - num mod base)/base
wend
Num2Str = right(string(lens,"0") & num & ret,lens)
End Function

Private Function Str2Num(str,base)
'GPS (2005-8-11)
dim ret
ret = 0
for i=1 to len(str)
ret = ret *base + cint(mid(str,i,1))
next
Str2Num=ret
End Function

Private Function BinVal(bin)
'GPS (2002-8-11)
dim ret
ret = 0
for i = lenb(bin) to 1 step -1
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal=ret
End Function

Private Function BinVal2(bin)
'GPS (2002-8-11)
dim ret
ret = 0
for i = 1 to lenb(bin)
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal2=ret
End Function

'///以下是调用代码///
Function getImageSize(filespec)
'GPS (2002-8-11)
dim ret(3)
aso.LoadFromFile(filespec)
bFlag=aso.read( 还有疑问请扣 KISS 844476679如果对我的回答满意请采纳

7. asp如何实现文件上传功能

基本原理是:采用ADO Stream对象的BinaryRead方法将FORM中的所有数据读出,从中截取出所需的文件数据,以二进制文件方式存盘。

下面是上传文件页面的一个例子:

<html>

<body>

<form name="Upload" Method="Post" Enctype="multipart/form-data" Action="Upload.asp">

<input type="file" name="FileName">

<INPUT TYPE="Submit" VALUE="Upload"></TD>

</form>

</body>

</html>

(7)asp上传扩展阅读

几种文件上传技术的比较

1、基于HTTP协议

该方法需要编程者利用第三方软件,如DELPHI、VB等,在应用程序中先进行HTTP协议编程,然后将待上传文件内容按HTTP协议的格式打包,最后向WEB服务器发送上传的请求报文,从而实现文件的上传。

因为DELPHI和VB不能编写完整的WEB网络程序,只能编写WEB小应用程序,因此,该方法只用于功能受限的网络应用。

2、基于VB(或DELPHI等)开发的文件上传组件

该方法利用VB(或DELPHI等编程语言)开发ASP服务器组件,实现特定的文件上传服务。它首先利用ASP表单功能将文件(二进制格式)从用户端上传到服务器端,然后使用VB开发的组件,对二进制文件进行处理,成为可以正常读写的文件。

该方法要求编程者不仅掌握ASP语言,而且还能利用VB等第三方语言进行组件编程,增加了开发的难度。

3、基于数据库技术

该方法和上个方法有类似之处。不同的地方在于对上传的二进制文件的处理上。它使用数据库来保存二进制文件。无论是小型数据库还是大型数据库都提供了存储二进制数据的数据类型,只要以Append Chunk方式将数据存入相应的字段就可以了。

该方法虽然简单可行,但是因为每次上传的文件大小都是不一样的,因此,会对数据库的空间造成很大的浪费,降低了数据的访问速度;并且使得文件只能在数据库环境下进行访问,造成了很大的不便。

8. 求asp上传文件代码

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%

dim upfile_5xSoft_Stream
Class upload_5xSoft
dim Form,File,Version
Dim ReName '改名后的文件名 whyslr add at 05.1.21
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=" cjlaicyh上传程序 V 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
ReName = fixedFileName(right(getFileName(mFileName),4))'重命名文件whyslr add at 05.1.21
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
if form.Exists(mFormName) then'避免读取多选表单列表时出错whyslr modify at 05.1.21
old_Value = form(mFormName)
form.Remove(mFormName)
form.Add mFormName,old_Value & "," & mFormValue
else
form.Add mFormName,mFormValue
end if
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub

Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function

private function fixedFileName(file_Ext)'将文件改名whyslr add at 05.1.21
Dim temp_STR,randomize_Num
temp_STR = ""
randomize
randomize_Num = (cint(9999*rnd()) + 100)
tempSTR = replace(now()," ","")
tempSTR = replace(tempSTR,"-","")
tempSTR = replace(tempSTR,"上午","")
tempSTR = replace(tempSTR,"下午","")
tempSTR = replace(ucase(tempSTR),"AM","")
tempSTR = replace(ucase(tempSTR),"PM","")
tempSTR = replace(ucase(tempSTR),"GTS","")
tempSTR = replace(tempSTR,":","")
fixedFileName = tempSTR & randomize_Num & file_Ext
end function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart,isSafe
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
isSafe = chk_Safe(fullpath) '如果你的空间不支持fso请将这行注释掉、不然保存文件时会出错whyslr add at 05.1.21
SaveAs=0
end function

private Function chk_Safe(filePath)'检查上传过来的是否是asp文件whyslr add at 05.1.21
Dim str
Dim fsoObject
Dim fileObject
set fsoObject = server.CreateObject("scripting.filesystemobject")
set fileObject = fsoObject.openTextFile(filePath,1,0)

if isObject(fileObject) then
do while not fileObject.AtEndOfStream
str = fileObject.ReadAll
Loop
end if
fileObject.close()
set fileObject = nothing

if instr(server.HTMLEncode(str),"<%") > 0 and instr(server.HTMLEncode(str),"%>") > 0 and fsoObject.fileExists(filePath) then
fsoObject.deleteFile filePath,true
chk_Safe = false
else
chk_Safe = true
end if
set fsoObject = nothing

end function
End Class
%>
<html>
<head> <%
dim FileName
set FileName=Request.Cookies("UserId")
if FileName="" then
response.write "帐号不存在[ <a href=# onclick=history.go(-1)>返回</a> ]"
else
dim upload,file,formName,formPath
set upload=new upload_5xSoft ''建立上传对象
formPath=upload.form("filepath") ''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.filesize<10 or file.filesize>200*1000 then
response.write "<font size=9>请先选择200K以下的图片文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
else
file.SaveAs Server.mappath("..\UserImages\"& FileName &".jpg")'file.FileName) ''保存文件
response.write"<meta http-equiv='refresh' content='0;url=UserSet.asp'>"'redirect "UserSet.asp"'"<font size=2>头像修改成功 [ <a href=fileup.asp>返回</a> ]</font>"
end if
set file=nothing
next
set upload=nothing
end if
%>

<title>文件上传</title>
</head>
<body>

</body>
</html>

9. ASP文件上传

<%
return=chrB(13)&chrB(10)'构造一个回车换行符号
aa=request.BinaryRead(request.TotalBytes)

set st1=server.CreateObject("adodb.stream")
st1.mode=3
st1.type=1
st1.open
st1.write aa

'LeftB LeftB函数从字符串的起始处提取指定数目的字节
divider=leftB(aa,clng(instrb(aa,return))-1)'使用 CInt 或 CLng 函数强制进行整数运算
datastart=instrb(aa,return&return)
'result = InStrB( [起始位置], 源字符串, 要查找的字符串 )
dataend=instrb(datastart,aa,divider)
set st2 = Server.CreateObject("adodb.stream")
st2.Type = 1
st2.Mode =3
st2.Open
st1.position=datastart+3
st1.to st2, dataend-datastart-6
'---------------------------------------
ii1=instrb(1,aa,en)
dd1=instrb(ii1,aa,en&en)
cc1=midb(aa,ii1,dd1-ii1)
'-----------------------------------
set st3 = server.CreateObject("adodb.stream")
st3.mode=3
st3.type=2
st3.open
st3.writetext cc1 '将文本装入对象
st3.position=0
st3.charset="gb2312"
st3.position=2

bstr=st3.readtext()'读取指定长度的文本,不指定将读取全部
startpos=instrrev(bstr,"\")+1'instrrev返回某字符串在另一个字符串中最后出现的位置
posend=instrrev(bstr,"""")
jg=mid(bstr,startpos,posend-startpos)
st2.savetofile server.MapPath("./chen/") & "/" & jg,2
response.Write("您所上传的文件为:" & jg)
st1.close
st2.close
st3.close
set st1=nothing
set st2=nothing
set st3=nothing
%>

静态页
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form name="form1" enctype="multipart/form-data" method="post" action="11.asp">
<label>
<input type="file" name="fileField" id="fileField">
</label>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
</body>
</html>

10. ASP网站文件上传

index.htm index.asp default.htm default.asp 一般是这几个

热点内容
如何提高三星a7安卓版本 发布:2024-09-20 08:42:35 浏览:658
如何更换服务器网站 发布:2024-09-20 08:42:34 浏览:305
子弹算法 发布:2024-09-20 08:41:55 浏览:283
手机版网易我的世界服务器推荐 发布:2024-09-20 08:41:52 浏览:811
安卓x7怎么边打游戏边看视频 发布:2024-09-20 08:41:52 浏览:157
sql数据库安全 发布:2024-09-20 08:31:32 浏览:88
苹果连接id服务器出错是怎么回事 发布:2024-09-20 08:01:07 浏览:502
编程键是什么 发布:2024-09-20 07:52:47 浏览:651
学考密码重置要求的证件是什么 发布:2024-09-20 07:19:46 浏览:477
电脑主服务器怎么开机 发布:2024-09-20 07:19:07 浏览:728