asp怎樣上傳件到指定資料夾并在access中記錄路徑_第1頁
asp怎樣上傳件到指定資料夾并在access中記錄路徑_第2頁
asp怎樣上傳件到指定資料夾并在access中記錄路徑_第3頁
asp怎樣上傳件到指定資料夾并在access中記錄路徑_第4頁
asp怎樣上傳件到指定資料夾并在access中記錄路徑_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、asp 怎樣上傳文件到指定的文件夾,并在 access 中記錄路徑 想上傳文件到指定的文件夾, 并在 access 中記錄路徑, 在 asp 頁面中顯示所上傳的軟件, 點(diǎn) 擊直接下載功能。注意:是上傳文件,不是圖片。文件包括exe、 rar 、zip 、 doc、 jpg 等等。最佳答案上傳文件頁 index.asp 開始index.asp 代碼如下<SCRIPT language=JavaScript type=text/javascript>function a(htmlurl) var win window.open(htmlurl,"newwin",&q

2、uot;toolbar=no,location=no,directories=no,status=no,me nubar=no,scrollbars=yes,resizable=no,width=300,height=10,left=380,top=380");</SCRIPT><form name="zc" action="index.asp" method="post"><table width="100%" border="0" cellspacin

3、g="0" cellpadding="0" ><tr><td height="30" align="right" style="color:#666">汽車照片: </td><td><input type="text" name="qczp" class="zc_input" maxlength="100" value="<%=session

4、("qczp")%>" readonly></td><td bgcolor="#E7F8F8" style="color:#666"><input type="button" value=" 上傳圖片 " onClick="a('uploadprod.asp');" name="button" style="color:#666; width:60px; height:20px;

5、"></td></tr></form></table>上傳文件頁 index.asp 結(jié)束uploadprod.asp 選擇圖片上傳 開始uploadprod.asp 代碼如下<!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="

6、/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title> 上傳圖片 </title><link href="./images/cnge_wy.css" rel="stylesheet" type="text/css" /><script> function check()va

7、r mf=document.up;if (mf.image.value.length<4)alert(" 請選擇需要上傳的圖片 ."); mf.image.focus();return false;return true;</script><script language="JavaScript">if (window.Event) document.captureEvents(Event.MOUSEUP);function nocontextmenu()event.cancelBubble = true event.ret

8、urnValue = false;return false;function norightclick(e)if (window.Event)if (e.which = 2 | e.which = 3) return false;elseif (event.button = 2 | event.button = 3) event.cancelBubble = true event.returnValue = false; return false;document.oncontextmenu = nocontextmenu; / for IE5+ document.onmousedown =

9、norightclick; / for all others </script></head> <body onselectstart="return false" oncopy="return false" oncut="return false" onpaste="return false" oncontextmenu="return false"><%response.buffer=trueconst page_level=1%><ta

10、ble width="300" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="2" align="center" height="25" style="font-weight:bold;"> 上傳圖片 </td></tr><form name="

11、up" method="post" action="uploadprod2.asp" enctype="multipart/form-data" onsubmit='return check();'><tr><td width="50%" align="right" height="25">選擇圖片: </td><td width="50%"><input type=&q

12、uot;file" name="image" style="border:1px solid #cdcdcd;"></td></tr><tr><td colspan="2" height="25" align="center"><input type="submit" value="提 交 "name="Submit" style="width:45px;

13、height:18px; border:1px solid #cdcdcd; color:#666; background-color:#FFFFFF;"><input type="reset" value=" 重 置 " style="width:45px; height:18px; border:1px solid #cdcdcd; color:#666; background-color:#FFFFFF;"></td></tr></form></table&g

14、t;</body></html>上傳文件頁 uploadprod.asp 結(jié)束判斷文件以及文件是否存在則上傳 uploadprod2.asp 開始uploadprod2.asp 源代碼<!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN""/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"

15、><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title> 圖片上傳 </title><link href="./images/cnge_wy.css" rel="stylesheet" type="text/css" /> <script language="JavaScript">if

16、(window.Event) document.captureEvents(Event.MOUSEUP);function nocontextmenu()event.cancelBubble = true event.returnValue = false;return false;function norightclick(e)if (window.Event)if (e.which = 2 | e.which = 3)return false;elseif (event.button = 2 | event.button = 3)event.cancelBubble = true even

17、t.returnValue = false;return false;document.oncontextmenu = nocontextmenu; / for IE5+ document.onmousedown = norightclick; / for all others </script></head>false"<body onselectstart="return false" oncopy="return false" oncut="return onpaste="return f

18、alse" oncontextmenu="return false"><% response.buffer=truesession("path1")=""const page_level=1%><!-#include file=zupload.asp-><%AllowFileExtStr = "jpg,gif,png,bmp"dim IDdim upload,path,file1,filename1set upload=new upload_5xSoft' 建立

19、上傳對象' 圖片上傳formPath="./Carpic/"'上傳圖片目錄' 開始上傳圖片set file1=upload.file("image")filename1=year(now()&"-"&month(now()&"-"&day(now()&"_"&hour(now()&"-"&Minute (now()&"-"&Second(now() &a

20、mp; right(file1.FileName,4)if file1.FileSize>0 then'如果 FileSize > 0說明有文件數(shù)據(jù)FileExtName=mid (file1.FileName,InStrRev (file1.FileName, ".")+1)if CheckFileType(AllowFileExtStr,FileExtName) = False then<br>的response.Write file1.FileName & "<br><font color=red&g

21、t; 文件:不允許上傳! 上傳文件類型有: " & AllowFileExtStr &"</font>"response.Write "<br>"response.Write " 你 IP:"&Replace(Request.ServerVariables("REMOTE_ADDR"),"'","")&""response.Write "<br>"re

22、sponse.write "你的操作已被系統(tǒng)所記錄! "response.End()end iffile1.SaveAs Server.mappath(formPath&filename1)' 保存文件' 上傳圖片成功path1= "/Carpic/"&filename1elseresponse.write " 請選擇要插入的圖片文件 "end ifsession("qczp")=path1%><p> 圖片上傳成功 .<script language=java

23、script>alert(" 圖片上傳成功! ");opener.document.zc.qczp.value="<%=path1%>"window.close();</script><%set file1=nothingFunction CheckFileType(AllowExtStr,FileExtName)Dim i,AllowArrayAllowArray = Split(AllowExtStr,",")FileExtName = LCase(FileExtName)CheckFileTy

24、pe = FalseFor i = LBound(AllowArray) to UBound(AllowArray)if LCase(AllowArray(i) = LCase(FileExtName) thenCheckFileType = Trueend ifororNextif FileExtName="asp" or FileExtName="asa" or FileExtName="aspx" FileExtName="php" or FileExtName="php3" or Fil

25、eExtName="php4" FileExtName="php5" or FileExtName="exe" thenCheckFileType = Falseend ifEnd Function%>%></body></html>判斷文件以及文件是否存在則上傳 uploadprod2.asp 結(jié)束另外需要一個 上傳組件 文件為 zupload.asp 開始代碼如下<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> dim Data_5xsoftClass

26、upload_5xsoftdim objForm,objFile,VersionPublic function Form(strForm)strForm=lcase(strForm)if not objForm.exists(strForm) thenForm=""elseForm=objForm(strForm)end ifend functionPublic function File(strFile) strFile=lcase(strFile) if not objFile.exists(strFile) then set File=new FileInfoelse

27、set File=objFile(strFile)end ifend functionPrivate Sub Class_Initializedim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile dim iFileSize,sFilePath,sFileType,sFormValue,sFileNamedim iFindStart,iFindEnddim iFormStart,iFormEnd,sFormName Version=" 上傳程序 Version 2.0" s

28、et objForm=Server.CreateObject("Scripting.Dictionary") set objFile=Server.CreateObject("Scripting.Dictionary") if Request.TotalBytes<1 then Exit Subset tStream = Server.CreateObject("adodb.stream") set Data_5xsoft = Server.CreateObject("adodb.stream") Data_

29、5xsoft.Type = 1Data_5xsoft.Mode =3 Data_5xsoft.OpenData_5xsoft.Write Request.BinaryRead(Request.TotalBytes) Data_5xsoft.Position=0RequestData =Data_5xsoft.ReadiFormStart = 1iFormEnd = LenB(RequestData) vbCrlf = chrB(13) & chrB(10) sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf

30、)-1) iStart = LenB (sStart)iFormStart=iFormStart+iStart+1 while (iFormStart + 10) < iFormEnd iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3 tStream.Type = 1tStream.Mode =3 tStream.OpenData_5xsoft.Position = iFormStartData_5xsoft.CopyTo tStream,iInfoEnd-iFormStart tStream.Position

31、 = 0 tStream.Type = 2tStream.Charset ="gb2312"sInfo = tStream.ReadTexttStream.Close' 取得表單項(xiàng)目名稱iFormStart = InStrB(iInfoEnd,RequestData,sStart) iFindStart = InStr(22,sInfo,"name=""",1)+6 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFormName = lcase(M

32、id (sinfo,iFindStart,iFindEnd-iFindStart) ' 如果是文件if InStr (45,sInfo,"filename=""",1) > 0 thenset theFile=new FileInfo' 取得文件名iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFileName

33、 = Mid (sinfo,iFindStart,iFindEnd-iFindStart) theFile.FileName=getFileName(sFileName) theFile.FilePath=getFilePath(sFileName)' 取得文件類型iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr(iFindStart,sInfo,vbCr) theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindSt

34、art) theFile.FileStart =iInfoEndtheFile.FileSize = iFormStart -iInfoEnd -3 theFile.FormName=sFormName if not objFile.Exists(sFormName) thenobjFile.add sFormName,theFileend ifelse' 如果是表單項(xiàng)目 tStream.Type =1 tStream.Mode =3 tStream.Open Data_5xsoft.Position = iInfoEnd Data_5xsoft.CopyTo tStream,iFor

35、mStart-iInfoEnd-3 tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312"sFormValue = tStream.ReadText tStream.Closeif objForm.Exists(sFormName) thenobjForm(sFormName)=objForm(sFormName)&", "&sFormValue elseobjForm.Add sFormName,sFormValue end if end ifiFormStart=iFormStart+iStart+1wendRequestData="" set tStream =nothingEnd SubPrivate Sub Class_Terminate if Request.TotalBytes>0 then objForm.RemoveAll objFile.RemoveAll set objForm=nothing set objFile=nothingDat

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論