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

webhosting24:€28/年,日本NVMe3900X+Webvps

webhosting24决定从7月1日开始对日本机房的VPS进行NVMe和流量大升级,几乎是翻倍了硬盘和流量,当然前提是价格依旧不变。目前来看,国内过去走的是NTT直连,服务器托管机房应该是CDN77*(也就是datapacket.com),加上高性能平台(AMD Ryzen 9 3900X+NVMe),这样的日本VPS还是有相当大的性价比的。官方网站:https://www.webhosting...

NameCheap黑色星期五和网络礼拜一

如果我们较早关注NameCheap商家的朋友应该记得前几年商家黑色星期五和网络星期一的时候大促采用的闪购活动,每一个小时轮番变化一次促销活动而且限量的。那时候会导致拥挤官网打不开迟缓的问题。从去年开始,包括今年,NameCheap商家比较直接的告诉你黑色星期五和网络星期一为期6天的活动。没有给你限量的活动,只有限时六天,这个是到11月29日。如果我们有需要新注册、转入域名的可以参加,优惠力度还是比...

cera:秋季美国便宜VPS促销,低至24/月起,多款VPS配置,自带免费Windows

介绍:819云怎么样?819云创办于2019,由一家从2017年开始从业的idc行业商家创办,主要从事云服务器,和物理机器819云—-带来了9月最新的秋季便宜vps促销活动,一共4款便宜vps,从2~32G内存,支持Windows系统,…高速建站的美国vps位于洛杉矶cera机房,服务器接入1Gbps带宽,采用魔方管理系统,适合新手玩耍!官方网站:https://www.8...

asp 文件上传为你推荐
google竞价排名谷歌是靠什么关键词排名的?谷歌竞价有什么特点?有什么优势?工信部备案怎样在工信部进行域名备案?要详细百度手写百度为什么没有了在线手写输入法手机区号手机号码前怎样填写正确的国内区号?数码资源网有什么网站弄相片效果比较好的?免费免费建站可以不用钱免费做一个网站吗二层交换机什么是二层交换机和三层交换机???分词技术怎么在SEO中学会运用关键词分词技术网管工具网管软件好用吗?什么样的网管软件好呢?我想管理二十台电脑,让其中的四五台可以上网,其它的只能上局域网,谁能推荐一款软件吗?如果出钱买也可以!谢谢了!虚拟机软件下载谁有好用的虚拟机软件?
郑州服务器租用 vps论坛 dns是什么 a2hosting 空间打开慢 suspended 监控宝 云主机51web 发包服务器 个人域名 刀片服务器是什么 刀片服务器的优势 gtt 联通网站 免费邮件服务器 谷歌台湾 免费蓝钻 国外网页代理 汤博乐 cdn免备案空间 更多