文件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 = ""

Hostwinds:免费更换IP/优惠码美元VPS免费更换IP4.99,7月最新优惠码西雅图直连VPS

hostwinds怎么样?2021年7月最新 hostwinds 优惠码整理,Hostwinds 优惠套餐整理,Hostwinds 西雅图机房直连线路 VPS 推荐,目前最低仅需 $4.99 月付,并且可以免费更换 IP 地址。本文分享整理一下最新的 Hostwinds 优惠套餐,包括托管型 VPS、无托管型 VPS、Linux VPS、Windows VPS 等多种套餐。目前 Hostwinds...

美得云(20元)香港特价将军澳CTG+CN2云服务器

美得云成立于2021年,是一家云产品管理服务商(cloud)专业提供云计算服务、DDOS防护、网络安全服务、国内海外数据中心托管租用等业务、20000+用户的选择,43800+小时稳定运行香港特价将军澳CTG+CN2云服务器、采用高端CPU 优质CN2路线 SDD硬盘。香港CTG+CN22核2G3M20G数据盘25元点击购买香港CTG+CN2​2核2G5M30G数据盘39元点击购买香港CTG+CN...

HaBangNet(6.95美元/月)美国vps 5TB流量/德国vps 香港双向CN2 GIA VPS

HaBangNet支持支付宝和微信支付,只是价格偏贵,之前国内用户并不多。这次HaBangNet推出三个特价套餐,其中美国机房和德国机房价格也还可以,但是香港机房虽然是双向CN2 GIA线路,但是还是贵的惊人,需要美国和德国机房的可以参考下。HaBangNet是一家成立于2014年的香港IDC商家,中文译名:哈邦网络公司,主营中国香港、新加坡、澳大利亚、荷兰、美国、德国机房的虚拟主机、vps、专用...

asp 文件上传为你推荐
cornerradius如何给TextView加个圆角?中国电信互联星空中国电信宽带于互联星空的区别中国论坛大全甘肃论坛都有哪些?吴晓波频道买粉《充电时间》的节目跟《吴晓波频道》哪个好听?伪静态如何设置伪静态规则qq空间装扮qq空间怎么装扮godaddyGO DADDY服务器空间域名怎么样迅雷云点播账号求一个迅雷云点播vip的账号,只是看的,绝不动任何手脚。迅雷云点播账号求百度云或者迅雷云播账号密码2012年正月十五山西省太原市2012年正月十五活动的相关情况
免费域名解析 buyvm themeforest linkcloud ssh帐号 debian源 500m空间 最好的空间 dd444 昆明蜗牛家 微软服务器操作系统 怎么建立邮箱 网站在线扫描 raid10 百度云加速 中国电信网络测速 ebay注册 秒杀品 注册阿里云邮箱 国外网页代理 更多