您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“asp如何將本地的文件上傳到服務(wù)器”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“asp如何將本地的文件上傳到服務(wù)器”吧!
今天我們講解如何利用asp的上傳功能將本地的文件上傳到服務(wù)器上。
最簡系統(tǒng)包括下面三個(gè)文件:
upload.htm --上傳口文件,選擇本地文件
uploadimg.asp --上傳程序控制文件
upload_5xsoft.inc --無組件上傳類,此文件初學(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 說明有文件數(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="無組件上傳類 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"">頁面執(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)容是上傳文件的最簡化程式,請(qǐng)朋友們自己分析一下,學(xué)會(huì)本演練,asp一般的上傳功能就基本掌握了
到此,相信大家對(duì)“asp如何將本地的文件上傳到服務(wù)器”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。