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

2021年国内/国外便宜VPS主机/云服务器商家推荐整理

2021年各大云服务商竞争尤为激烈,因为云服务商家的竞争我们可以选择更加便宜的VPS或云服务器,这样成本更低,选择空间更大。但是,如果我们是建站用途或者是稳定项目的,不要太过于追求便宜VPS或便宜云服务器,更需要追求稳定和服务。不同的商家有不同的特点,而且任何商家和线路不可能一直稳定,我们需要做的就是定期观察和数据定期备份。下面,请跟云服务器网(yuntue.com)小编来看一下2021年国内/国...

萤光云(16元/月)高防云服务器自带50G防御

螢光云官網萤光云成立于2002年,是一家自有IDC的云厂商,主打高防云服务器产品。在国内有福州、北京、上海、台湾、香港CN2节点,还有华盛顿、河内、曼谷等海外节点。萤光云的高防云服务器自带50G防御,适合高防建站、游戏高防等业务。本次萤光云中秋云活动简单无套路,直接在原有价格上砍了一大刀,最低价格16元/月,而且有没有账户限制,新老客户都可以买,就是直接满满的诚意给大家送优惠了!官网首页:www....

LOCVPS新上日本软银线路VPS,原生IP,8折优惠促销

LOCVPS在农历新年之后新上架了日本大阪机房软银线路VPS主机,基于KVM架构,配备原生IP,适用全场8折优惠码,最低2GB内存套餐优惠后每月仅76元起。LOCVPS是一家成立于2012年的国人VPS服务商,提供中国香港、韩国、美国、日本、新加坡、德国、荷兰、俄罗斯等地区VPS服务器,基于KVM或XEN架构(推荐选择KVM),线路方面均选择国内直连或优化方案,访问延迟低,适合建站或远程办公使用。...

asp 文件上传为你推荐
湖南商标注册在湖南商标注册到底有什么用,不就是一个图标吗?湖南商标注册在湖南搞商标注册是代理好还是自己去好一点?湖南商标注册的流程又是什么样的呢?申请证书求高手教下怎么申请证书滚动代码来回滚动代码网易公开课怎么下载手机上的网易公开课的付费课程怎么下载??????xv播放器下载除了迅雷看看播放器还有什么播放器支持xv格式的视频?数据库损坏数据库坏了,怎么修复?xp系统停止服务XP系统为什么要停止服务?创维云电视功能创维电视怎么用,我买了个创维云电视,现在不知道怎么用手机往电视上传照片,谁能解答以下,云挂机快手极速版后台云挂机辅?助各位用了吗?在哪找的?
域名注册信息查询 域名备案中心 krypt photonvps 鲨鱼机 directadmin 免费博客空间 web服务器架设软件 bgp双线 怎么测试下载速度 91vps 云营销系统 dnspod 华为k3 金主 工信部icp备案查询 中国电信宽带测速 小夜博客 贵州电信 腾讯云平台 更多