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

asp文件上传

发布时间: 2022-01-08 15:45:37

⑴ ASP网站文件上传

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

⑵ ASP上传文件代码

1、2可以解决,3有点复杂,我对无组件上传也不是很熟悉,很久没有碰过了,
建议你使用别人做好的上传类,像无惧上传类、稻香老农的化境asp无组件上传类等都可以,有很多,都挺好用的。

关于1、2的问题可参照下面的解决办法,因为你的代码全写在一行,读起来太麻烦,所以我给拆开了。代码如下:

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

<body>
<%
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)

set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.to f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "未选择要上传的文件<a href='?'>重新上传</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
f.SaveToFile server.mappath("/images/"& h),2 '上传至“/images/”文件夹
f.Close
set f=Nothing
a.Close
set a=Nothing
response.write "<a href="&Server.URlEncode(h)&">"&h&"</a>"
end if
%>
<script language="javascript">
function checkupload(){
if(document.upload_form.fe.value ==""){
alert("未选择要上传的文件");
return false;
}
}
</script>
<form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())">
<input type="file" name="fe">
<input type="submit" value="上传" name="B1"></form>
</body>
</html>

⑶ asp如何上传文件,并保存到服务器端

可以使用无组件上传类,网上有下载的。你可以网络“asp无组件上传类”搜索

⑷ 求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>

⑸ asp 后台如何接收上传文件

我记得asp有一个request还是什么的来接收文件的。

看看这片文章

http://wenku..com/view/ba88e901bed5b9f3f90f1c96.html

⑹ 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>

(6)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方式将数据存入相应的字段就可以了。

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

⑺ 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>

⑻ asp上传文件到服务器的代码怎么写

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
'On Error Resume Next
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.to f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "未选择要上传的文件<a href='?'>重新上传</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j

h = Mid(h, InStrRev(h, "filename=""") + 10) '这是我帮你添加的,文件名的获取没有正确
f.SaveToFile server.mappath("/EXCEL/"& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing
'response.write "<a href="&Server.URlEncode(h)&">"&h&"</a>"
end if
If Err.number<> 0 Then
response.Write err.number
response.Write err.Description
Response.End
End If
%>
<script language="javascript">
function checkupload() {
if (document.upload_form.fe.value == "") {
alert("未选择要上传的文件");
return false;
}
}
</script>
<form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())">
<input type="file" name="fe"/>
<input type="submit" value="上传" name="B1"/>
</form>
</body>
</html>

⑼ ASP文件上传问题

首先说一下
你的这个判断 是根据用户名上传文件的扩展名进行判断
用的是截取字符串的格式,所以造成即使他使用ASP文件里边写入代码或者IFRAME或script等只要扩展名改成JPG或者GIF都可以通过你的判断向你的网站中植入木马程序.

以下相关是解决ASP图片上传漏洞的函数

请认真查看后使用

<%
'******************************************************************
'CheckFileType 函数用来检查文件是否为图片文件
'参数filename是本地文件的路径
'如果是文件jpeg,gif,bmp,png图片中的一种,函数返回true,否则返回false
'******************************************************************

const adTypeBinary=1

dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)

function CheckFileType(filename)
on error resume next
CheckFileType=false
filename=LCase(filename)
dim fstream,fileExt,stamp,i
fileExt=mid(filename,InStrRev(filename,".")+1)
set fstream=Server.createobject("ADODB.Stream")
fstream.Open
fstream.Type=adTypeBinary
fstream.LoadFromFile filename
fstream.position=0
select case fileExt
case "jpg","jpeg"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
next
case "gif"
stamp=fstream.read(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
next
case "png"
stamp=fstream.read(4)
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
next
case "bmp"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
next
end select
fstream.Close
set fseteam=nothing
if err.number<>0 then CheckFileType=false
end function
%>

那么在应用的时候
CheckFileType(server.mappath("cnbruce.jpg"))
或者
CheckFileType("F:/web/164/images/cnbruce.jpg"))

反正即是检测验证本地物理地址的图像文件类型,返回 true 或 false值

所以这个情况应用在图像上传中,目前的办法是先允许该“伪图像”文件的上传,接着使用以上的自定义函数判断该文件是否符合图像的规范,若是木马伪装的图像文件则FSO删除之,比如:

file.SaveAs Server.mappath(filename) '保存文件
If not CheckFileType(Server.mappath(filename)) then
response.write "错误的图像格式"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ficn = fso.GetFile(Server.mappath(filename))
ficn.delete
set ficn=nothing
set fso=nothing
response.end
end if

ASP上传漏洞还利用"\0"对filepath进行手脚操作
http://www.cnbruce.com/blog/showlog.asp?cat_id=32&log_id=635

针对这样的情况可使用如下函数

function TrueStr(fileTrue)
str_len=len(fileTrue)
pos=Instr(fileTrue,chr(0))
if pos=0 or pos=str_len then
TrueStr=true
else
TrueStr=false
end if
end function

接着就可判断后再做文件的上传

if TrueStr(filename)=false then
response.write "非法文件"
response.end
end if

file.SaveAs Server.mappath(filename)

⑽ 简单asp上传文件代码

我还是一点一点用一个实例来说明的吧,客户端HTML如下。要浏览上传附件,
我们通过<input type="file">元素,但是一定要注意必须设置form的enctype
属性为"multipart/form-data":
<form method="post" action="upload.asp"
enctype="multipart/form-data">
<label>
<input type="file" name="file1" />
</label>

<input type="text" name="filename" value="default filename"/>

<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</form>
在后台asp程序中,以前获取表单提交的ASCII 数据,非常的容易。但是如果
需要获取上传的文件,就必须使用Request对象的BinaryRead方法来读取。Bin
aryRead方法是对当前输入流进行指定字节数的二进制读取,有点需要注意的
是,一旦使用BinaryRead 方法后,再也不能使用Request.Form 或
Request.QueryString 集合了。结合Request对象的TotalBytes属性,可以将
所有表单提交的数据全部变成二进制,不过这些数据都是经过编码的。首先让
我们来看看这些数据是如何编码的,有无什么规律可循,编段代码,在代码中
我们将BinaryRead读取的二进制转化为文本,输出出来,在后台的upload.asp
中(注意该示例不要上传大文件,否则可能会造成浏览器死掉):
<%
Dim biData, PostData
Size = Request.TotalBytes
biData = Request.BinaryRead(Size)
PostData = BinaryToString(biData,Size)
Response.Write "<pre>" & PostData & "</pre>" '使用pre,原样输出格式
' 借助RecordSet将二进制流转化成文本
Function BinaryToString(biData,Size)
Const adLongVarChar = 201
Set RS = createObject("ADODB.Recordset")
RS.Fields.Append "mBinary", adLongVarChar, Size
RS.Open
RS.AddNew
RS("mBinary").AppendChunk(biData)
RS.update
BinaryToString = RS("mBinary").Value
RS.Close
End Function
%>

热点内容
建立云存储 发布:2024-05-03 21:04:03 浏览:74
socket编程php 发布:2024-05-03 20:12:50 浏览:207
坦洲邮政局可以解压吗 发布:2024-05-03 20:09:55 浏览:732
二级程序编译答案 发布:2024-05-03 18:41:35 浏览:654
领动自动精英版是哪个配置 发布:2024-05-03 18:37:30 浏览:151
java编译器中cd什么意思 发布:2024-05-03 18:36:00 浏览:390
传奇服务器如何刷钱 发布:2024-05-03 18:36:00 浏览:978
安卓版twitter怎么注册 发布:2024-05-03 18:28:05 浏览:894
Python逻辑优先级 发布:2024-05-03 18:26:14 浏览:268
linux查看svn密码 发布:2024-05-03 18:12:47 浏览:805