文件asp怎样上传文件到指定的文件夹并在access中记录路径

asp 文件上传  时间:2021-02-09  阅读:()

asp怎样上传文件到指定的文件夹并在acc ess中记录路径

想上传文件到指定的文件夹并在acc ess中记录路径在asp页面中显示所上传的软件 点击直接下载功能。

注意是上传文件不是图片。文件包括e xe、 rar、 zip、 doc、 jpg等等。

最佳答案上传文件页index.asp 开始

-----------------------------index.asp代码如下

<SCRIP T language=JavaS cript type=text/javas cript>funct ion a(htmlu rl) {var win = windo w.open(htmlu rl, "newwi n", "toolb ar=no, locat ion=no,direc tories=no, statu s=no,menub ar=no, scrol lbars =yes,resiz able=no,width =300,height=10, left=380, top=380") ;

}

</SCRIP T>

<form name="zc" actio n="index.asp" metho d="post">

<table width="100%" border="0" cellspacing="0" cellpadding="0" >

<tr>

<td height="30" align="right " style="color :#666">汽车照片 </td>

<td><input type="text" name="qczp" class ="zc_in put" maxle ngth="100" value="<%=sessi on("qczp")%>" readonly></td>

<td bgcol or="#E7F8F8" style="color :#666"><input type="button" value="上传图片" onCli ck="a('uploa dprod.asp' ) ;" name="butto n" style="color :#666; width :60px;heigh t:20px;"></td>

</tr>

</form>

</table >

上传文件页 ind e x.as p 结束

uploa dprod.asp选择图片上传开始

uploa dprod.asp代码如下

<!DOCTY PE html PUBLI C "-//W3C//DTD XHTML 1.0 Trans ition al//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-trans ition al.dtd">

<html xmlns="http://www.w3.org/1999/xhtml ">

<head>

<meta http-equiv="Content-Type" content="text/html ; chars et=gb2312" />

<title >上传图片</title>

<link href=". ./image s/cnge_wy.css" rel="style sheet " type="text/css" />

<script>funct ion check ()

{var mf=docum ent.up;if (mf. image .value.lengt h<4)

{alert ("请选择需要上传的图片.") ;mf. image .focus () ;retur n false ;

}retur n true;

}

</script>

<scrip t language="JavaS cript">if (windo w.Event)docum ent.captu reEve nts(Event.MOUSEUP) ;funct ion nocon textm enu()

{event .cance lBubb le = trueevent .returnValue = false ;return false ;

}funct ion norightcli ck(e)

{if (windo w.Event)

{if (e.which == 2 | | e.which == 3)return false ;

}elseif (event .butto n == 2 | | event .butto n == 3)

{event .cance lBubb le = trueevent .returnValu e = false ;return false ;

}

}docum ent.oncon textm enu = nocon textmenu; // for IE5+docum ent.onmou sedown = norightcli ck; // for all other s</script>

</head>

<body onsel ectst art="returnfalse"oncopy="returnfalse"oncut="returnfalse"onpaste="return false" oncontextmenu="return false ">

<%respo nse.buffer=trueconst page_level=1

%>

<table width="300" border="0" cellspacing="0" cellp adding="0" align="center">

<tr>

<td colsp an="2" align="center" height="25" style="font-weight:bold;">上传图片</td>

</tr>

<form name="up" metho d="post" actio n="uploa dprod 2.asp" encty pe="multipart/form-data" onsub mit='return check () ; ' >

<tr>

<td width="50%" align="right "height="25">选择图片 </td>

<td width ="50%"><input type="file" name="image " style ="borde r:1px solid#cdcdc d;"></td>

</tr>

<tr>

<td colsp an="2" height="25" align="center"><input type="submi t" value="提交" name="Submi t" style="width :45px; heigh t:18px; borde r:1px solid #cdcdc d; color

:#666; backg round-color :#FFFFF F;">

<input type="reset " value ="重置" style ="width :45px; heigh t:18px; borde r:1pxsolid #cdcdc d; color :#666; backg round-color :#FFFFF F;"></td>

</tr>

</form>

</tab l e >

</body>

</html>

上传文件页uploa dprod.asp 结束

-----------------------------

判断文件以及文件是否存在则上传uploa dprod 2.asp 开始

-----------------------------uploa dprod 2.asp 源代码

<!DOCTY PE html PUBLI C "-//W3C//DTD XHTML 1.0 Trans ition al//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-trans ition al.dtd">

<html xmlns="http://www.w3.org/1999/xhtml ">

<head>

<meta http-equiv="Content-Type" content="text/html ; chars et=gb2312" />

<title >图片上传</title>

<link href=". ./image s/cnge_wy.css" rel="style sheet " type="text/css" />

<scrip t language="JavaS cript ">if (windo w.Event)docum ent.captu reEve nts(Event .MOUSEUP) ;funct ion nocon textm enu()

{event .cance lBubb le = trueevent .returnValue = false ;return false ;

}funct ion norightcli ck(e)

{if (windo w.Event)

{if (e.which == 2 | | e.which == 3)return false ;

}elseif (event .butto n == 2 | | event .butto n == 3)

{event .cance lBubb le = trueevent .returnValu e = false ;return false ;

}

}docum ent.oncon textm enu = nocon textmenu; // for IE5+docum ent.onmou sedown = norightcli ck; // for all other s

</script>

</head>

<body onsel ectst art="returnfalse"oncopy="returnfalse"oncut="returnfalse"onpaste="return false" oncontextmenu="return false ">

<% respo nse.buffer=truesessi on("path1 ")=""const page_level=1

%>

<!--#include file=zupload.asp-->

<%

Allow FileExtStr = "jpg,gif,png,bmp"dim IDdim upload,path,file1 ,filename1set uploa d=new upload_5xSoft'建立上传对象

'图片上传formP ath=". ./Carpi c/"'上传图片目录

'开始上传图片set file1=upload.file("image")filen ame1=year(now() )&"-"&month

(now() )&"-"&day(now() )&"_"&hour(now() )&"-"&Minut e(now() )&"-"&Secon d(now() ) &right (file1 .FileN ame,4)if file1 .FileS ize>0 then'如果FileS ize > 0说明有文件数据

FileE xtName=mid (file1 .FileName, InStr Rev (file1 .FileName, ". ")+1)if Check FileType(AllowFileExtStr,FileExtNam e) = False thenrespo nse.Write file1 .FileName&"<br><font color=red>文件不允许上传 <br>上传文件类型有 " & AllowFileExtStr &"</font>"respo nse.Write "<br>"respo nse.Write "你的 IP:"&Repla ce(Reque st.Serve rVari ables ("REMOT E_ADDR") , "' ", "")&""respo nse.Write "<br>"respo nse.write "你的操作已被系统所记录 "respo nse.End()end iffile1 .SaveA s Serve r.mappa th(formP ath&filen ame1) '保存文件

'上传图片成功path1="/Carpi c/"&filename1elserespo nse.write "请选择要插入的图片文件"end ifsessi on("qczp")=path1

%>

<p>图片上传成功.

<scrip t language=javas cript>alert ("图片上传成功 ") ;opene r.document. zc.qczp.value="<%=path1%>";window.close () ;

</script>

<%set file1=nothing

Funct ion Check FileT ype(AllowExtSt r,FileE xtNam e)

Dim i,AllowArray

Allow Array = Split (AllowExtSt r,", ")

FileE xtNam e= LCase (FileE xtNam e)

Check FileType = False

For i = LBoun d(AllowArray) to UBoun d(AllowArray)if LCase (Allow Array (i) ) = LCase (FileE xtNam e) then

Check FileT ype = Trueend if

Nextif FileE xtNam e="asp" or FileE xtName="asa" or FileE xtName="aspx" or FileE xtName="php" or FileE xtNam e="php3" or FileE xtNam e="php4" or FileE xtNam e="php5" orFileE xtNam e="exe" then

Check FileType = Falseend if

End Funct ion

%>

%>

</body>

</html>

判断文件以及文件是否存在则上传uploadprod 2.asp 结束

另外需要一个上传组件文件为 zupload.asp 开始

-----------------------------

代码如下

<SCRIP T RUNAT=SERVE R LANGU AGE=VBSCR IPT>dim Data_5xsof t

Class upload_5xsoftdim objFo rm,objFi le,Versi on

Publi c funct ion Form(strFo rm)strFo rm=lcase (strFo rm)if not objFo rm.exist s(strForm) then

Form=""

else

Form=objFo rm(strFo rm)end ifend funct ion

Publi c funct ion File(strFi le)strFi le=lcase (strFi le)if not objFi le.exist s(strFi le) thenset File=new FileInfoelseset File=objFi le(strFi le)end ifend funct ion

Private Sub Class_Init ialize

dim Reque stDat a,sStart,vbCrl f,sInfo,iInfoStart,iInfoEnd, tStream, iStart,theFi ledim iFile Size, sFilePath, sFileType, sFormValue,sFile Namedim iFind Start,iFindEnddim iForm Start,iForm End, sFormName

Versi on="上传程序Version 2.0"set objFo rm=Server.Creat eObject("Scripting.Dicti onary")set objFi le=Server.Creat eObject("Scripting.Dicti onary")if Reque st.TotalBytes<1 then Exit Subset tStre am= Server.Creat eObject("adodb.stream")set Data_5xsof t= Server.Creat eObject("adodb.stream")

Data_5xsof t.Type = 1

Data_5xsof t.Mode =3

Data_5xsof t.Open

Data_5xsof t.Write Reque st.BinaryRead (Reque st.Total Bytes)

Data_5xsof t.Posit ion=0

Reque stDat a=Data_5xsof t.ReadiForm Start = 1iForm End = LenB(Reque stDat a)vbCrl f= chrB(13) & chrB(10)sStar t= MidB(Reque stDat a, 1, InStrB(iFormStart,Reque stDat a,vbCrl f)-1)iStar t= LenB (sStar t)iForm Start=iForm Start+iStar t+1while (iForm Start + 10) < iForm EndiInfo End = InStr B(iFormStart,Reque stDat a,vbCrl f& vbCrl f)+3tStre am.Type = 1tStre am.Mode =3tStre am.Open

Data_5xsof t.Posit ion = iForm Start

Data_5xsof t.CopyTo tStre am, iInfoEnd-iFormStarttStre am.Posit ion = 0tStre am.Type = 2tStre am.Chars et ="gb2312"sInfo = tStre am.ReadT exttStream.Close

'取得表单项目名称iForm Start = InStrB(iInfoEnd,Reque stDat a,sStar t)iFind Start = InStr (22, sInfo,"name=""", 1)+6iFind End = InStr (iFind Start,sInfo,"""", 1)sForm Name = lcase (Mid (sinfo,iFind Start,iFind End-iFind Start))'如果是文件if InStr (45, sInfo,"filename=""", 1) > 0 thenset theFi le=new FileI nfo

'取得文件名iFind Start = InStr (iFindEnd, sInfo,"filename=""", 1)+10iFind End = InStr (iFind Start,sInfo,"""", 1)sFile Name = Mid (sinfo,iFindStart,iFindEnd-iFind Start)theFi le.FileName=getFi leName(sFileName)theFi le.FileP ath=getFi lePat h(sFileName)

'取得文件类型iFind Start = InStr (iFindEnd, sInfo,"Conte nt-Type: ", 1)+14iFind End = InStr (iFind Start,sInfo,vbCr)theFi le.FileT ype =Mid (sinfo,iFindStart,iFindEnd-iFind Start)theFi le.FileS tart =iInfoEndtheFi le.FileS ize = iFormStart -iInfo End -3theFi le.FormN ame=sFormNameif not objFi le.Exist s(sFormName) thenobjFi le.add sFormName, theFi leend ifelse

'如果是表单项目tStre am.Type =1tStre am.Mode =3tStre am.Open

Data_5xsof t.Posit ion = iInfo End

Data_5xsof t.CopyTo tStre am, iFormStart-iInfo End-3tStre am.Posit ion = 0tStre am.Type = 2tStre am.Chars et ="gb2312"sForm Value = tStre am.ReadT exttStream.Closeif objFo rm.Exist s(sFormName) then

objFo rm(sFormName)=objFo rm(sFormName)&", "&sFormValueelseobjFo rm.Add sFormName, sFormValueend ifend ifiForm Start=iForm Start+iStar t+1wend

Reque stDat a=""set tStream=nothing

End Sub

Priva te Sub Class_Terminateif Reque st.TotalBytes>0 thenobjFo rm.Remov eAllobjFi le.Remov eAllset objForm=nothingset objFi le=nothing

Data_5xsof t.Closeset Data_5xsof t=nothingend if

End Sub

Priva te funct ion GetFi lePat h(FullP ath)

If FullP ath <> "" Then

GetFi lePat h= left(FullP ath, InStrRev(FullP ath, "\") )Else

GetFi lePat h= ""

End If

End funct ion

Priva te funct ion GetFi leNam e(FullP ath)

If FullP ath <> "" Then

GetFi leName= mid(FullP ath, InStr Rev(FullP ath, "\")+1)Else

GetFi leNam e= ""

End If

End funct ion

End Class

Class FileInfodim FormN ame,FileName,FilePath,FileS ize,FileType,FileS tartPrivate Sub Class_Init ialize

FileName = ""

数脉科技:六月优惠促销,免备案香港物理服务器,E3-1230v2处理器16G内存,350元/月

数脉科技六月优惠促销发布了!数脉科技对香港自营机房的香港服务器进行超低价促销,可选择30M、50M、100Mbps的优质bgp网络。更大带宽可在选购时选择同样享受优惠,目前仅提供HKBGP、阿里云产品,香港CN2、产品优惠码续费有效,仅限新购,每个客户可使用于一个订单。新客户可以立减400元,或者选择对应的机器用相应的优惠码,有需要的朋友可以尝试一下。点击进入:数脉科技官方网站地址数脉科技是一家成...

gcorelabs远东khabarovsk伯力Cloud云服务器测评,告诉你gcorelabs云服务器怎么样

说明一下:gcorelabs的俄罗斯远东机房“伯力”既有“Virtual servers”也有“CLOUD SERVICES”,前者是VPS,后者是云服务器,不是一回事;由于平日大家习惯把VPS和云服务器当做一回事儿,所以这里要特别说明一下。本次测评的是gcorelabs的cloud,也就是云服务器。 官方网站:https://gcorelabs.com 支持:数字加密货币、信用卡、PayPal...

#推荐# cmivps:全场7折,香港不限流量VPS,支持Windows系统

cmivps香港VPS带来了3个新消息:(1)双向流量改为单向流量,相当于流量间接扩大一倍;(2)Hong Kong 2T、Hong Kong 3T、Hong Kong 无限流量,这三款VPS开始支持Windows系统,如果需要中文版Windows系统请下单付款完成之后发ticket要求官方更改即可;(3)全场7折年付、8折月付优惠,优惠码有效期一个月!官方网站:https://www.cmivp...

asp 文件上传为你推荐
刷网站权重如何提高网站权重和流量windows优化大师怎么用windows优化大师怎么用﹖微信如何建群在微信里怎么创建一个群别人可以加入扫描二维码的加入微信如何建群微信建群怎么建直播加速有没有软件使已经下载好了的视频播放加速,例如30分钟的视频15分钟或者20分钟播放完商标注册查询官网怎么查商标有没有注册二层交换机请教:二层交换机是干什么用的啊?怎么上传音乐如何将电脑上的音乐传到MP3上宽带接入服务器网络已连接,可无法连接到服务器为什么?网络已连接,可无法连接到服务服务器连接异常手机WIFI检查显示主服务器连接异常,怎么办
上海虚拟主机 虚拟主机mysql 汉邦高科域名注册 免费域名申请 如何注册中文域名 lnmp 新加坡服务器 秒解服务器 英文简历模板word 免费ftp空间申请 150邮箱 架设服务器 国外免费全能空间 网站卫士 adroit umax120 metalink paypal注册教程 空间首页登陆 域名与空间 更多