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

LightNode($7.71/月)香港cn2精品线路

LightNode官网LightNode是一家位于香港的VPS服务商.提供基于KVM虚拟化技术的VPS.在提供全球常见节点的同时,还具备东南亚地区、中国香港等边缘节点.满足开发者建站,游戏应用,外贸电商等应用场景的需求。为用户带来高性能服务器以及优质的服务的同时还提供丰厚的促销活动,新用户注册最高送$20。注册用户带新客即可得10%返佣。商家支持PayPal,支付宝等支付方式。官网:https:/...

licloud:$39/月,香港物理服务器,30M带宽,e3-1230v3/16G内存/1T硬盘

licloud官方消息:当前对香港机房的接近100台物理机(香港服务器)进行打折处理,30Mbps带宽,低至不到40美元/月,速度快,性价比高,跑绝大多数项目都是绰绰有余了。该款香港服务器自带启动、关闭、一键重装功能,正常工作日内30~60分钟交货(不包括非工作日)。 官方网站:https://licloud.io 特价香港物理服务器 CPU:e3-1230v2(4核心、8线程、3.3GH...

RAKsmart:美国圣何塞服务器限量秒杀$30/月起;美国/韩国/日本站群服务器每月189美元起

RAKsmart怎么样?RAKsmart是一家由华人运营的国外主机商,提供的产品包括独立服务器租用和VPS等,可选数据中心包括美国加州圣何塞、洛杉矶、中国香港、韩国、日本、荷兰等国家和地区数据中心(部分自营),支持使用PayPal、支付宝等付款方式,网站可选中文网页,提供中文客服支持。本月商家继续提供每日限量秒杀服务器月付30.62美元起,除了常规服务器外,商家美国/韩国/日本站群服务器、1-10...

asp 文件上传为你推荐
photoimpact教程Ulead PhotoImpact 如何把英文版的变成中文的!缓冲区溢出教程适合黑客初级学者使用的黑客工具有那些 、邮箱打不开怎么办163邮箱突然打不开了怎么办怎么在qq空间里添加背景音乐如何在qq空间中添加背景音乐今日热点怎么删除如何彻底删除今日热点9flash在“属性”对话框中的“Move”后面的框中输入Flash动画文件的绝对路径及文件名,这句话怎么操作?网店推广网站网店怎么推广?硬盘人克隆一个人需要多少人多长时间啊vbscript教程vbs 学习方法以及 vbs 实例 有编程基础奇虎论坛360有论坛中心?
高防服务器租用选锐一 合租服务器 2019年感恩节 winhost cdn服务器 国外服务器 英语简历模板word panel1 小米数据库 建立邮箱 电子邮件服务器 静态空间 免费phpmysql空间 中国电信测速网站 服务器论坛 wordpress中文主题 lamp怎么读 深圳域名 学生服务器 测速电信 更多