asp將本地的文件上傳到服務(wù)器
今天我們講解如何利用asp的上傳功能將本地的文件上傳到服務(wù)器上。
最簡(jiǎn)系統(tǒng)包括下面三個(gè)文件:
upload.htm --上傳口文件,選擇本地文件
uploadimg.asp --上傳程序控制文件
upload_5xsoft.inc --無(wú)組件上傳類,此文件初學(xué)者不用學(xué)習(xí),只要會(huì)用就可以了
upload.htm內(nèi)容————上傳口文件,選擇本地文件
<html> <head> </head> <body> <table width="80%" border="0" align="center"> <form name="form1" method="post" action="uploadimg.asp" enctype="multipart/form-data"> <tr> <td align="center"><input name="upfile" type="file" id="upfile"></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="上傳圖片"></td> </tr> </form> </table> </body> </html>
uploadimg.asp內(nèi)容————上傳程序控制文件
<!--#include FILE="upload_5xsoft.inc"--> <% dim upload,file,filepath filepath="UPLOAD/" set upload=new upload_5xSoft ''建立上傳對(duì)象 for each formName in upload.file ''列出所有上傳了的文件 set file=upload.file(formName) ''生成一個(gè)文件對(duì)象 if file.FileSize>0 then ''如果 FileSize > 0 說(shuō)明有文件數(shù)據(jù) fname = file.filename file.SaveAs Server.mappath(filepath&fname) ''保存文件 end if set file=nothing next set upload=nothing ''刪除此對(duì)象
upload_5xsoft.inc內(nèi)容————此文件內(nèi)容不屬于本演練程序內(nèi)容,本演練應(yīng)用此類的方法
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> dim oUpFileStream Class upload_5xSoft dim Form,File,Version Private Sub Class_Initialize dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName dim iFindStart,iFindEnd dim iFormStart,iFormEnd,sFormName Version="無(wú)組件上傳類 Version 0.93" set Form=Server.CreateObject("Scripting.Dictionary") set File=Server.CreateObject("Scripting.Dictionary") if Request.TotalBytes<1 then Exit Sub set tStream = Server.CreateObject("adodb.stream") set oUpFileStream = Server.CreateObject("adodb.stream") oUpFileStream.Type = 1 oUpFileStream.Mode =3 oUpFileStream.Open oUpFileStream.Write Request.BinaryRead(Request.TotalBytes) Response.Write "<font size=""2"">頁(yè)面執(zhí)行時(shí)間:"&FormatNumber((Timer() -time1)*1000,3)&"毫秒</font><br>" oUpFileStream.Position=0 RequestBinDate =oUpFileStream.Read iFormStart = 1 iFormEnd = LenB(RequestBinDate) bCrLf = chrB(13) & chrB(10) sStart = MidB(RequestBinDate,1, InStrB(iFormStart,RequestBinDate,bCrLf)-1) iStart = LenB (sStart) iFormStart=iFormStart+iStart+1 while (iFormStart + 10) < iFormEnd iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & bCrLf)+3 tStream.Type = 1 tStream.Mode =3 tStream.Open oUpFileStream.Position = iFormStart oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sInfo = tStream.ReadText '取得表單項(xiàng)目名稱 iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart) iFindStart = InStr(22,sInfo,"name=""",1)+6 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) '如果是文件 if InStr (45,sInfo,"filename=""",1) > 0 then set oFileInfo=new FileInfo '取得文件名 iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileName=getFileName(sFileName) oFileInfo.FilePath=getFilePath(sFileName) '取得文件類型 iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr(iFindStart,sInfo,vbCr) oFileInfo.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileStart =iInfoEnd oFileInfo.FileSize = iFormStart -iInfoEnd -3 oFileInfo.FormName=sFormName file.add sFormName,oFileInfo else '如果是表單項(xiàng)目 tStream.Close tStream.Type =1 tStream.Mode =3 tStream.Open oUpFileStream.Position = iInfoEnd oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-3 tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sFormvalue = tStream.ReadText form.Add sFormName,sFormvalue end if tStream.Close iFormStart=iFormStart+iStart+1 wend RequestBinDate="" set tStream =nothing End Sub Private Sub Class_Terminate if not Request.TotalBytes<1 then form.RemoveAll file.RemoveAll set form=nothing set file=nothing oUpFileStream.Close set oUpFileStream =nothing end if End Sub Private function GetFilePath(FullPath) If FullPath <> "" Then GetFilePath = left(FullPath,InStrRev(FullPath, "")) Else GetFilePath = "" End If End function Private function GetFileName(FullPath) If FullPath <> "" Then GetFileName = mid(FullPath,InStrRev(FullPath, "")+1) Else GetFileName = "" End If End function End Class Class FileInfo dim FormName,FileName,FilePath,FileSize,FileType,FileStart Private Sub Class_Initialize FileName = "" FilePath = "" FileSize = 0 FileStart= 0 FormName = "" FileType = "" End Sub Public function SaveAs(FullPath) dim oFileStream,ErrorChar,i SaveAs=1 if trim(fullpath)="" or right(fullpath,1)="/" then exit function set oFileStream=CreateObject("Adodb.Stream") oFileStream.Type=1 oFileStream.Mode=3 oFileStream.Open oUpFileStream.position=FileStart oUpFileStream.copyto oFileStream,FileSize oFileStream.SaveToFile FullPath,2 oFileStream.Close set oFileStream=nothing SaveAs=0 end function End Class </SCRIPT>
此文所訴的內(nèi)容是上傳文件的最簡(jiǎn)化程式,請(qǐng)朋友們自己分析一下,學(xué)會(huì)本演練,asp一般的上傳功能就基本掌握了。
- asp.net+FCKeditor上傳圖片顯示叉叉圖片無(wú)法顯示的問(wèn)題的解決方法
- asp.net fileupload控件上傳文件與多文件上傳
- ASP實(shí)現(xiàn)文件上傳的方法
- asp.net(c#)開(kāi)發(fā)中的文件上傳組件uploadify的使用方法(帶進(jìn)度條)
- asp.net MVC實(shí)現(xiàn)無(wú)組件上傳圖片實(shí)例介紹
- asp.net 多文件上傳,兼容IE6/7/8,提供完整代碼下載
- Asp.net實(shí)現(xiàn)MVC處理文件的上傳下載功能實(shí)例教程
- ASP.NET MVC實(shí)現(xiàn)圖片上傳、圖片預(yù)覽顯示
- asp.net(C#)中上傳大文件的幾中常見(jiàn)應(yīng)用方法
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
相關(guān)文章
ajaxToolkit:TextBoxWatermarkExtender演示與實(shí)現(xiàn)代碼
該控件的效果就是在TextBox控件上添加“水印”效果,也就是當(dāng)TextBox為空時(shí),顯示提示消息,一旦TextBox聚焦,樣式就消失,看起來(lái)還挺不錯(cuò)的嗎,感興趣的你可以了解下哦,希望本文對(duì)你有所幫助2013-01-01asp.net 選擇excel類型文件,利用Dos命令成批復(fù)制文件
選擇excel類型文件,利用Dos命令成批復(fù)制文件2009-12-12擴(kuò)展了Repeater控件的EmptyDataTemplate模板功能
Repeater控件是一個(gè)數(shù)據(jù)顯示控件,該控件允許通過(guò)為列表中顯示的每一項(xiàng)重復(fù)使用指定的模板來(lái)自定義布局2013-01-01[Asp.Net Core] 淺談Blazor Server Side
這篇文章主要介紹了[Asp.Net Core] Blazor Server Side 的相關(guān)資料,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作
眾所周知斷點(diǎn)對(duì)于Visual Studio調(diào)試過(guò)程是十分重要的,斷點(diǎn)的設(shè)置也是為了更好的進(jìn)行調(diào)試。下面這篇文章主要給大家介紹了關(guān)于Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作的相關(guān)資料,需要的朋友可以參考下2018-09-09.Net Core創(chuàng)建Api進(jìn)行文件上傳功能
這篇文章主要介紹了.Net Core創(chuàng)建Api進(jìn)行文件上傳,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03CheckBox為CheckBoxList實(shí)現(xiàn)全選或全取消選擇(js代碼實(shí)現(xiàn))
在管理商品后臺(tái)是,由于CheckBoxList的選擇太多,用戶需要一個(gè)全選或全取消的功能,這樣操作起來(lái)會(huì)提高效率同時(shí)可以減少誤點(diǎn)等,本文將教大家如何實(shí)現(xiàn),有需要的朋友可以參考下,望本文對(duì)你有所幫助2013-01-01.Net微信網(wǎng)頁(yè)開(kāi)發(fā)解決用戶在不同公眾號(hào)或在公眾號(hào)、移動(dòng)應(yīng)用之間帳號(hào)統(tǒng)一問(wèn)題
這篇文章主要介紹了.Net微信網(wǎng)頁(yè)開(kāi)發(fā)解決用戶在不同公眾號(hào)或在公眾號(hào)、移動(dòng)應(yīng)用之間帳號(hào)統(tǒng)一問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09