asp文件上传,asp文件上传js组件

http://www.itjxue.com  2023-01-12 16:08  来源:未知  点击次数: 

如何使用AspUpload组件上传文件

你好,试试以下的方法:一、摘要Asp组件有内置的、服务器安装时附带的,更多的是第三方提供的,今天来学习文件上传的其中一个组件aspupload组件使用方法。

二、aspupload组件的下载、安装或注册 1、asp组件的下载、安装

(1)可以从网上下载。

(2)直接双击后进行安装。

AspUpload组件下载2、asp上传组件的功能

a.限制上载文件的大小

b.设置用户的权限

c.修改文件属性

d.同时上载多个文件

e.能够将文件保存到数据库中

f.支持文件删除,自动生成与服务器上文件不同名的文件

g.拥有管理权限的用户甚至可以使用该控件进行远程注册

三、aspupload组件的简单应用

1、实例一(1.asp):通过代码实现三个文件的上传功能。

如下图所示:

(1)静态页面:1个表单,三个文件域,一个按钮,其中表单form的动作如下。 (2)其中客户端文件要注意几点:

* 文件上载提交表单(Form)的enctype必须指定为“multipart/form-data”

* 语句表示上载文件域,用户可以在该域中输入或选定文件。

* 传递一个参数act(名称可自己取),其值可以自己随便定,目的是触发上传事件。

(3)动态代码如下:

2、实例二(2.asp):修改程序1.asp,要求在上传文件后显示上传文件的文件名及大小。

增加如下代码: response.write("文件1是:

")response.write(upload.files(1).path)

response.write("文件2是:

")response.write(upload.files(2).path)

response.write("文件3是:

")

response.write(upload.files(3).path)

说明:

upload.files方法用来获取文件的相关属性,path是文件的路径,size是文件的大小。

3、实例三(3.asp):修改程序2.asp,要求上传的三个文件大小不能超过5K,如果上传的文件已经存在则要求不覆盖文件。

在上传之前增加如下代码:

upload.setmaxsize 5120,false

upload.overwritefiles=fals说明:

(1)upload.setmaxsize 5120,false 其功能为设置文件最大为5120字节,false参数说明当文件超过5120字节时则删除超过部分,true参数说明当文件超过5120字节时则出错。

(2)upload.overwritefiles=false,其功能表示文件不进行覆盖,如果上传同样文件名的文件,上传后文件名自动会在后面添加一个数字。

四、自学第二个上传文件的组件

1、Lyfupload组件的下载

2、学习此组件的安装或注册

3、通过课本例子进行文件的上传

五、问题

1、传到学校里服务器172.18.0.7运行时出现以下错误,Server.CreateObject 失败

分析原因:学校服务器不支持aspupload上传组件

2、如果服务器不支持aspupload等上传组件,请大家使用无组件上传功能(编写代码),见书本上P322,此类代码比较复杂,同学们能够拿来使用,无须自己编写。

3、大家在网上申请个人空间时要看清服务器支持哪些组件,这样有利于编写代码。

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.copyto 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,cc)+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怎么上传啊?

既然是上传,那么一定是有服务器或空间(如果是自己的服务器,那么现在服务器里面创建站点),那么就应该有空间的ftp地址、账号及密码,使用上传工具(举例:flashfxp、cuteftp等),录入ftp信息后,打开服务器空间,界面一般分左右两边,左边是本机,右边是服务器(也可以自己设置),一般服务器里面会有个wwwroot的文件夹,从左边找到本机要上传的asp文件,把根目录的程序上传到wwwroot文件夹下即可。

【急】asp如何文件上传

下面是用ASP写的,已经测试过

文件上传有个非常重要的地方,就是限制格式,严格规定只有什么格式才可以上传

否则可能会被黑客利用

这些光用DW自动生成是做不出来的 要自己写代码

%

if Request.QueryString("submit")="swf_Pic" then

uploadpath=""

uploadsize="1024"

uploadtype="jpg/gif/png/bmp"

Set Uprequest=new UpLoadClass

Uprequest.SavePath=uploadpath

Uprequest.MaxSize=uploadsize*1024

Uprequest.FileType=uploadtype

AutoSave=true

Uprequest.open

if Uprequest.form("file_Err")0 then

select case Uprequest.form("file_Err")

case 1:str="div style=""padding-top:5px;padding-bottom:5px;"" font color=blue上传不成功!文件超过"uploadsize"k [a href='javascript:history.go(-1)'重新上传/a]/font/div"

case 2:str="div style=""padding-top:5px;padding-bottom:5px;"" font color=blue上传不成功!文件格式不对 [a href='javascript:history.go(-1)']重新上传/a]/font/div"

case 3:str="div style=""padding-top:5px;padding-bottom:5px;"" font color=blue上传不成功!文件太大且格式不对 [a href='javascript:history.go(-1)'重新上传/a]/font/div"

end select

response.write str

else

response.write "script language=""javascript""parent.form.swf_Pic.value='"Uprequest.SavePathUprequest.Form("file")"';"

response.write "/script"

response.write "div style=""padding-top:5px;padding-bottom:5px;"" font color=red文件上传成功/font [a href='javascript:history.go(-1)'重新上传/a]/div"

end if

Set Uprequest=nothing

end if

response.write "form name=form action=?action=swf_Picsubmit=swf_Pic method=post enctype=multipart/form-data"

response.write "input type=file name=file class='tx' size='20' "

response.write "input type=submit name=submit value=上传 class=""tx1"""

response.write "/form"

'============================================================上传函数

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 = 153600

p_FileType = "jpg/gif"

p_SavePath = ""

p_AutoSave = 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 lngRequestSize1 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,bCrLfbCrLf)+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=strFileItemstrSplitstrInam

if binItem.Size0 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_AutoSave2 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_SavePathstrFnam),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=strFormItemstrSplitstrInam

objForm.Add strInam,strTemp

end if

end if

binItem.Close()

p_start = p_end+intSeparator+2

loop Until p_start+3lngRequestSize

FormItem=split(strFormItem,strSplit)

FileItem=split(strFileItem,strSplit)

End Sub

Private Function GetTimeStr()

lngTime=lngTime+1

GetTimeStr=strDatelngTime

End Function

Private Function GetFerr(lngFsiz,strFext)

dim intFerr

intFerr=0

if lngFsizp_MaxSize and p_MaxSize0 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_Error2 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 intFerr0 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_SavePathstrFnam),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

%

asp文件上传:文件上传 源代码

! #include FILE="upload inc" % dim upload file formName formPath iCount filename fileExt set upload=new upload_ xSoft 建立上传对象 formPath="uploadimages/" ? 在目录后加(/) if right(formPath )"/" then formPath=formPath"/" iCount= for each formName in upload file 列出所有上传了的文件 ?set file=upload file(formName)? 生成一个文件对象 ?if file filesize then ? response write "font size= br请先选择你要上传的图片 [ a href=# onclick=history go( )重新上传/a ]/font" ?response end ?end if ? ?if file filesize then ? response write "font size= br图片大小超过了限制 [ a href=# onclick=history go( )重新上传/a ]/font" ?response end ?end if

fileExt=lcase(right(file filename ))

if fileEXT" jpg" and fileEXT" gif" then ? response write "font size= br文件格式只能为jpg和gif格式 [ a href=# onclick=history go( )重新上传/a ]/font" ?response end ?end if ?randomize ?ranNum=int( *rnd)+ ?filename=formPathyear(now)month(now)day(now)hour(now)minute(now)second(now)fileExt ?filename =year(now)month(now)day(now)hour(now)minute(now)second(now)fileExt ? ?if file FileSize then???????? 如果 FileSize 说明有文件数据 ?file SaveAs Server mappath(filename)?? 保存文件 response write "scriptparent form img value= "FileName " /script"

iCount=iCount+ ?end if ?set file=nothing next set upload=nothing? 删除此对象

Response Write "img src= "" /UpLoad/UpLoadImages/"FileName " onload = DrawImage(this) " ?response end %

下面是upload inc的代码

SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT dim upfile_ xSoft_Stream Class upload_ xSoft dim Form File Version Private Sub Class_Initialize dim iStart iFileNameStart iFileNameEnd iEnd vbEnter iFormStart iFormEnd theFile dim strDiv mFormName mFormValue mFileName mFileSize mFilePath iDivLen mStr if Request TotalBytes then Exit Sub set Form=CreateObject("Scripting Dictionary") set File=CreateObject("Scripting Dictionary") set upfile_ xSoft_Stream=CreateObject("Adodb Stream") upfile_ xSoft_Stream mode= upfile_ xSoft_Stream type= upfile_ xSoft_Stream open upfile_ xSoft_Stream write Request BinaryRead(Request TotalBytes) vbEnter=Chr( )Chr( ) iDivLen=inString( vbEnter)+ strDiv=subString( iDivLen) iFormStart=iDivLen iFormEnd=inString(iformStart strDiv) while iFormStart iFormEnd ? iStart=inString(iFormStart "name=""") ? iEnd=inString(iStart+ """") ? mFormName=subString(iStart+ iEnd iStart ) ? iFileNameStart=inString(iEnd+ "filename=""") ? if iFileNameStart and iFileNameStartiFormEnd then ?? iFileNameEnd=inString(iFileNameStart+ """") ?? mFileName=subString(iFileNameStart+ iFileNameEnd iFileNameStart ) ?? iStart=inString(iFileNameEnd+ vbEntervbEnter) ?? iEnd=inString(iStart+ vbEnterstrDiv) ?? if iEndiStart then ??? mFileSize=iEnd iStart ?? else ??? mFileSize= ?? end if ?? set theFile=new FileInfo ?? theFile FileName=getFileName(mFileName) ?? theFile FilePath=getFilePath(mFileName) ?? theFile FileSize=mFileSize ?? theFile FileStart=iStart+ ?? theFile FormName=FormName ?? file add mFormName theFile ? else ?? iStart=inString(iEnd+ vbEntervbEnter) ?? iEnd=inString(iStart+ vbEnterstrDiv)

if iEndiStart then ??? mFormValue=subString(iStart+ iEnd iStart ) ?? else ??? mFormValue="" ?? end if ?? form Add mFormName mFormValue ? end if

iFormStart=iformEnd+iDivLen ? iFormEnd=inString(iformStart strDiv) wend End Sub

Private Function subString(theStart theLen) ?dim i c stemp ?upfile_ xSoft_Stream Position=theStart ?stemp="" ?for i= to theLen ?? if upfile_ xSoft_Stream EOS then Exit for ?? c=ascB(upfile_ xSoft_Stream Read( )) ?? If c Then ??? if upfile_ xSoft_Stream EOS then Exit for ??? stemp=stempChr(AscW(ChrB(AscB(upfile_ xSoft_Stream Read( )))ChrB(c))) ??? i=i+ ?? else ??? stemp=stempChr(c) ?? End If ?Next ?subString=stemp End function

Private Function inString(theStart varStr) ?dim i j bt theLen str ?InString= ?Str=toByte(varStr) ?theLen=LenB(Str) ?for i=theStart to upfile_ xSoft_Stream Size theLen ?? if iupfile_ xSoft_Stream size then exit Function ?? upfile_ xSoft_Stream Position=i ?? if AscB(upfile_ xSoft_Stream Read( ))=AscB(midB(Str )) then ??? InString=i ??? for j= to theLen ????? if upfile_ xSoft_Stream EOS then ??????? inString= ??????? Exit for ????? end if ????? if AscB(upfile_ xSoft_Stream Read( ))AscB(MidB(Str j )) then ??????? InString= ??????? Exit For ????? end if ??? next ??? if InString then Exit Function ?? end if ?next End Function

Private Sub Class_Terminate? ? form RemoveAll ? file RemoveAll ? set form=nothing ? set file=nothing ? upfile_ xSoft_Stream close ? set upfile_ xSoft_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 "")+ ) ? Else ?? GetFileName = "" ? End If ?End? function

Private function toByte(Str) ?? dim i iCode c iLow iHigh ?? toByte="" ?? For i= To Len(Str) ?? c=mid(Str i ) ?? iCode =Asc(c) ?? If iCode Then iCode = iCode + ?? If iCode Then ???? iLow = Left(Hex(Asc(c)) ) ???? iHigh =Right(Hex(Asc(c)) ) ???? toByte = toByte chrB("H"iLow) chrB("H"iHigh) ?? Else ???? toByte = toByte chrB(AscB(c)) ?? End If ?? Next ?End function End Class

lishixinzhi/Article/program/net/201311/14198

如何用ASP上传图片

分类: 电脑/网络 程序设计 其他编程语言

解析:

文件一upload_5xsoft.inc

SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT

dim Data_5xsoft

Class upload_5xsoft

dim objForm,objFile,Version

Public function Form(strForm)

strForm=lcase(strForm)

if not objForm.exists(strForm) then

Form=""

else

Form=objForm(strForm)

end if

end function

Public function File(strFile)

strFile=lcase(strFile)

if not objFile.exists(strFile) then

set File=new FileInfo

else

set File=objFile(strFile)

end if

end function

Private Sub Class_Initialize

dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile

dim iFileSize,sFilePath,sFileType,sFormValue,sFileName

dim iFindStart,iFindEnd

dim iFormStart,iFormEnd,sFormName

Version="化境HTTP上传程序 Version 2.0"

set objForm=Server.CreateObject("Scripting.Dictionary")

set objFile=Server.CreateObject("Scripting.Dictionary")

if Request.TotalBytes1 then Exit Sub

set tStream = Server.CreateObject("adodb.stream")

set Data_5xsoft = Server.CreateObject("adodb.stream")

Data_5xsoft.Type = 1

Data_5xsoft.Mode =3

Data_5xsoft.Open

Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)

Data_5xsoft.Position=0

RequestData =Data_5xsoft.Read

iFormStart = 1

iFormEnd = LenB(RequestData)

vbCrlf = chrB(13) chrB(10)

sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)

iStart = LenB (sStart)

iFormStart=iFormStart+iStart+1

while (iFormStart + 10) iFormEnd

iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf vbCrlf)+3

tStream.Type = 1

tStream.Mode =3

tStream.Open

Data_5xsoft.Position = iFormStart

Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart

tStream.Position = 0

tStream.Type = 2

tStream.Charset ="gb2312"

sInfo = tStream.ReadText

tStream.Close

'取得表单项目名称

iFormStart = InStrB(iInfoEnd,RequestData,sStart)

iFindStart = InStr(22,sInfo,"name=""",1)+6

iFindEnd = InStr(iFindStart,sInfo,"""",1)

sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))

'如果是文件

if InStr (45,sInfo,"filename=""",1) 0 then

set theFile=new FileInfo

'取得文件名

iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10

iFindEnd = InStr(iFindStart,sInfo,"""",1)

sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)

theFile.FileName=getFileName(sFileName)

theFile.FilePath=getFilePath(sFileName)

'取得文件类型

iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14

iFindEnd = InStr(iFindStart,sInfo,vbCr)

theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)

theFile.FileStart =iInfoEnd

theFile.FileSize = iFormStart -iInfoEnd -3

theFile.FormName=sFormName

if not objFile.Exists(sFormName) then

objFile.add sFormName,theFile

end if

else

'如果是表单项目

tStream.Type =1

tStream.Mode =3

tStream.Open

Data_5xsoft.Position = iInfoEnd

Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3

tStream.Position = 0

tStream.Type = 2

tStream.Charset ="gb2312"

sFormValue = tStream.ReadText

tStream.Close

if objForm.Exists(sFormName) then

objForm(sFormName)=objForm(sFormName)", "sFormValue

else

objForm.Add sFormName,sFormValue

end if

end if

iFormStart=iFormStart+iStart+1

wend

RequestData=""

set tStream =nothing

End Sub

Private Sub Class_Terminate

if Request.TotalBytes0 then

objForm.RemoveAll

objFile.RemoveAll

set objForm=nothing

set objFile=nothing

Data_5xsoft.Close

set Data_5xsoft =nothing

end if

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

End Class

Class FileInfo

dim FormName,FileName,FilePath,FileSize,FileType,FileStart

Private Sub Class_Initialize

FileName = ""

FilePath = ""

FileSize = 0

FileStart= 0

FormName = ""

FileType = ""

End Sub

Public function SaveAs(FullPath)

dim dr,ErrorChar,i

SaveAs=true

if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function

set dr=CreateObject("Adodb.Stream")

dr.Mode=3

dr.Type=1

dr.Open

Data_5xsoft.position=FileStart

Data_5xsoft.copyto dr,FileSize

dr.SaveToFile FullPath,2

dr.Close

set dr=nothing

SaveAs=false

end function

End Class

/SCRIPT

文件二 upload

form name=form1 method="post" action="upfile" enctype="multipart/form-data"

照片上传

input type=file name=file1

input type=submit value="提 交"

/form

文件三 upfile

!--#include FILE="upload_5xsoft.inc"--

link href="MAIN1024.css" rel="stylesheet" type=text/css

%

Set upload = New upload_5xsoft

f= Server.MapPath("pic")"/"

Set file = upload.file("file1")

n = right(file.FileName,4)

s=replace(now(),":","")

s=replace(now(),"-","")

s=replace(now()," ","")

file.SaveAs fsn

session("image")=sn

Response.Write "图片上传成功"

%

(责任编辑:IT教学网)

更多

推荐测评专题文章