當前位置:首頁 » 文件管理 » asp文件上傳

asp文件上傳

發布時間: 2022-01-08 15:45:37

⑴ ASP網站文件上傳

index.htm index.asp default.htm default.asp 一般是這幾個

⑵ ASP上傳文件代碼

1、2可以解決,3有點復雜,我對無組件上傳也不是很熟悉,很久沒有碰過了,
建議你使用別人做好的上傳類,像無懼上傳類、稻香老農的化境asp無組件上傳類等都可以,有很多,都挺好用的。

關於1、2的問題可參照下面的解決辦法,因為你的代碼全寫在一行,讀起來太麻煩,所以我給拆開了。代碼如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
</head>

<body>
<%
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)

set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.to f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "未選擇要上傳的文件<a href='?'>重新上傳</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
f.SaveToFile server.mappath("/images/"& h),2 '上傳至「/images/」文件夾
f.Close
set f=Nothing
a.Close
set a=Nothing
response.write "<a href="&Server.URlEncode(h)&">"&h&"</a>"
end if
%>
<script language="javascript">
function checkupload(){
if(document.upload_form.fe.value ==""){
alert("未選擇要上傳的文件");
return false;
}
}
</script>
<form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())">
<input type="file" name="fe">
<input type="submit" value="上傳" name="B1"></form>
</body>
</html>

⑶ asp如何上傳文件,並保存到伺服器端

可以使用無組件上傳類,網上有下載的。你可以網路「asp無組件上傳類」搜索

⑷ 求asp上傳文件代碼

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%

dim upfile_5xSoft_Stream
Class upload_5xSoft
dim Form,File,Version
Dim ReName '改名後的文件名 whyslr add at 05.1.21
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=" cjlaicyh上傳程序 V 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
ReName = fixedFileName(right(getFileName(mFileName),4))'重命名文件whyslr add at 05.1.21
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
if form.Exists(mFormName) then'避免讀取多選表單列表時出錯whyslr modify at 05.1.21
old_Value = form(mFormName)
form.Remove(mFormName)
form.Add mFormName,old_Value & "," & mFormValue
else
form.Add mFormName,mFormValue
end if
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
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

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function

private function fixedFileName(file_Ext)'將文件改名whyslr add at 05.1.21
Dim temp_STR,randomize_Num
temp_STR = ""
randomize
randomize_Num = (cint(9999*rnd()) + 100)
tempSTR = replace(now()," ","")
tempSTR = replace(tempSTR,"-","")
tempSTR = replace(tempSTR,"上午","")
tempSTR = replace(tempSTR,"下午","")
tempSTR = replace(ucase(tempSTR),"AM","")
tempSTR = replace(ucase(tempSTR),"PM","")
tempSTR = replace(ucase(tempSTR),"GTS","")
tempSTR = replace(tempSTR,":","")
fixedFileName = tempSTR & randomize_Num & file_Ext
end function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart,isSafe
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
isSafe = chk_Safe(fullpath) '如果你的空間不支持fso請將這行注釋掉、不然保存文件時會出錯whyslr add at 05.1.21
SaveAs=0
end function

private Function chk_Safe(filePath)'檢查上傳過來的是否是asp文件whyslr add at 05.1.21
Dim str
Dim fsoObject
Dim fileObject
set fsoObject = server.CreateObject("scripting.filesystemobject")
set fileObject = fsoObject.openTextFile(filePath,1,0)

if isObject(fileObject) then
do while not fileObject.AtEndOfStream
str = fileObject.ReadAll
Loop
end if
fileObject.close()
set fileObject = nothing

if instr(server.HTMLEncode(str),"<%") > 0 and instr(server.HTMLEncode(str),"%>") > 0 and fsoObject.fileExists(filePath) then
fsoObject.deleteFile filePath,true
chk_Safe = false
else
chk_Safe = true
end if
set fsoObject = nothing

end function
End Class
%>
<html>
<head> <%
dim FileName
set FileName=Request.Cookies("UserId")
if FileName="" then
response.write "帳號不存在[ <a href=# onclick=history.go(-1)>返回</a> ]"
else
dim upload,file,formName,formPath
set upload=new upload_5xSoft ''建立上傳對象
formPath=upload.form("filepath") ''在目錄後加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上傳了的文件
set file=upload.file(formName) ''生成一個文件對象
if file.filesize<10 or file.filesize>200*1000 then
response.write "<font size=9>請先選擇200K以下的圖片文件 [ <a href=# onclick=history.go(-1)>重新上傳</a> ]</font>"
response.end
else
file.SaveAs Server.mappath("..\UserImages\"& FileName &".jpg")'file.FileName) ''保存文件
response.write"<meta http-equiv='refresh' content='0;url=UserSet.asp'>"'redirect "UserSet.asp"'"<font size=2>頭像修改成功 [ <a href=fileup.asp>返回</a> ]</font>"
end if
set file=nothing
next
set upload=nothing
end if
%>

<title>文件上傳</title>
</head>
<body>

</body>
</html>

⑸ asp 後台如何接收上傳文件

我記得asp有一個request還是什麼的來接收文件的。

看看這片文章

http://wenku..com/view/ba88e901bed5b9f3f90f1c96.html

⑹ asp如何實現文件上傳功能

基本原理是:採用ADO Stream對象的BinaryRead方法將FORM中的所有數據讀出,從中截取出所需的文件數據,以二進制文件方式存檔。

下面是上傳文件頁面的一個例子:

<html>

<body>

<form name="Upload" Method="Post" Enctype="multipart/form-data" Action="Upload.asp">

<input type="file" name="FileName">

<INPUT TYPE="Submit" VALUE="Upload"></TD>

</form>

</body>

</html>

(6)asp文件上傳擴展閱讀

幾種文件上傳技術的比較

1、基於HTTP協議

該方法需要編程者利用第三方軟體,如DELPHI、VB等,在應用程序中先進行HTTP協議編程,然後將待上傳文件內容按HTTP協議的格式打包,最後向WEB伺服器發送上傳的請求報文,從而實現文件的上傳。

因為DELPHI和VB不能編寫完整的WEB網路程序,只能編寫WEB小應用程序,因此,該方法只用於功能受限的網路應用。

2、基於VB(或DELPHI等)開發的文件上傳組件

該方法利用VB(或DELPHI等編程語言)開發ASP伺服器組件,實現特定的文件上傳服務。它首先利用ASP表單功能將文件(二進制格式)從用戶端上傳到伺服器端,然後使用VB開發的組件,對二進制文件進行處理,成為可以正常讀寫的文件。

該方法要求編程者不僅掌握ASP語言,而且還能利用VB等第三方語言進行組件編程,增加了開發的難度。

3、基於資料庫技術

該方法和上個方法有類似之處。不同的地方在於對上傳的二進制文件的處理上。它使用資料庫來保存二進制文件。無論是小型資料庫還是大型資料庫都提供了存儲二進制數據的數據類型,只要以Append Chunk方式將數據存入相應的欄位就可以了。

該方法雖然簡單可行,但是因為每次上傳的文件大小都是不一樣的,因此,會對資料庫的空間造成很大的浪費,降低了數據的訪問速度;並且使得文件只能在資料庫環境下進行訪問,造成了很大的不便。

⑺ ASP文件上傳

<%
return=chrB(13)&chrB(10)'構造一個回車換行符號
aa=request.BinaryRead(request.TotalBytes)

set st1=server.CreateObject("adodb.stream")
st1.mode=3
st1.type=1
st1.open
st1.write aa

'LeftB LeftB函數從字元串的起始處提取指定數目的位元組
divider=leftB(aa,clng(instrb(aa,return))-1)'使用 CInt 或 CLng 函數強制進行整數運算
datastart=instrb(aa,return&return)
'result = InStrB( [起始位置], 源字元串, 要查找的字元串 )
dataend=instrb(datastart,aa,divider)
set st2 = Server.CreateObject("adodb.stream")
st2.Type = 1
st2.Mode =3
st2.Open
st1.position=datastart+3
st1.to st2, dataend-datastart-6
'---------------------------------------
ii1=instrb(1,aa,en)
dd1=instrb(ii1,aa,en&en)
cc1=midb(aa,ii1,dd1-ii1)
'-----------------------------------
set st3 = server.CreateObject("adodb.stream")
st3.mode=3
st3.type=2
st3.open
st3.writetext cc1 '將文本裝入對象
st3.position=0
st3.charset="gb2312"
st3.position=2

bstr=st3.readtext()'讀取指定長度的文本,不指定將讀取全部
startpos=instrrev(bstr,"\")+1'instrrev返回某字元串在另一個字元串中最後出現的位置
posend=instrrev(bstr,"""")
jg=mid(bstr,startpos,posend-startpos)
st2.savetofile server.MapPath("./chen/") & "/" & jg,2
response.Write("您所上傳的文件為:" & jg)
st1.close
st2.close
st3.close
set st1=nothing
set st2=nothing
set st3=nothing
%>

靜態頁
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
</head>

<body>
<form name="form1" enctype="multipart/form-data" method="post" action="11.asp">
<label>
<input type="file" name="fileField" id="fileField">
</label>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
</body>
</html>

⑻ asp上傳文件到伺服器的代碼怎麼寫

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
</head>
<body>
<%
'On Error Resume Next
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.to f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "未選擇要上傳的文件<a href='?'>重新上傳</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j

h = Mid(h, InStrRev(h, "filename=""") + 10) '這是我幫你添加的,文件名的獲取沒有正確
f.SaveToFile server.mappath("/EXCEL/"& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing
'response.write "<a href="&Server.URlEncode(h)&">"&h&"</a>"
end if
If Err.number<> 0 Then
response.Write err.number
response.Write err.Description
Response.End
End If
%>
<script language="javascript">
function checkupload() {
if (document.upload_form.fe.value == "") {
alert("未選擇要上傳的文件");
return false;
}
}
</script>
<form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())">
<input type="file" name="fe"/>
<input type="submit" value="上傳" name="B1"/>
</form>
</body>
</html>

⑼ ASP文件上傳問題

首先說一下
你的這個判斷 是根據用戶名上傳文件的擴展名進行判斷
用的是截取字元串的格式,所以造成即使他使用ASP文件里邊寫入代碼或者IFRAME或script等只要擴展名改成JPG或者GIF都可以通過你的判斷向你的網站中植入木馬程序.

以下相關是解決ASP圖片上傳漏洞的函數

請認真查看後使用

<%
'******************************************************************
'CheckFileType 函數用來檢查文件是否為圖片文件
'參數filename是本地文件的路徑
'如果是文件jpeg,gif,bmp,png圖片中的一種,函數返回true,否則返回false
'******************************************************************

const adTypeBinary=1

dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)

function CheckFileType(filename)
on error resume next
CheckFileType=false
filename=LCase(filename)
dim fstream,fileExt,stamp,i
fileExt=mid(filename,InStrRev(filename,".")+1)
set fstream=Server.createobject("ADODB.Stream")
fstream.Open
fstream.Type=adTypeBinary
fstream.LoadFromFile filename
fstream.position=0
select case fileExt
case "jpg","jpeg"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
next
case "gif"
stamp=fstream.read(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
next
case "png"
stamp=fstream.read(4)
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
next
case "bmp"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
next
end select
fstream.Close
set fseteam=nothing
if err.number<>0 then CheckFileType=false
end function
%>

那麼在應用的時候
CheckFileType(server.mappath("cnbruce.jpg"))
或者
CheckFileType("F:/web/164/images/cnbruce.jpg"))

反正即是檢測驗證本地物理地址的圖像文件類型,返回 true 或 false值

所以這個情況應用在圖像上傳中,目前的辦法是先允許該「偽圖像」文件的上傳,接著使用以上的自定義函數判斷該文件是否符合圖像的規范,若是木馬偽裝的圖像文件則FSO刪除之,比如:

file.SaveAs Server.mappath(filename) '保存文件
If not CheckFileType(Server.mappath(filename)) then
response.write "錯誤的圖像格式"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ficn = fso.GetFile(Server.mappath(filename))
ficn.delete
set ficn=nothing
set fso=nothing
response.end
end if

ASP上傳漏洞還利用"\0"對filepath進行手腳操作
http://www.cnbruce.com/blog/showlog.asp?cat_id=32&log_id=635

針對這樣的情況可使用如下函數

function TrueStr(fileTrue)
str_len=len(fileTrue)
pos=Instr(fileTrue,chr(0))
if pos=0 or pos=str_len then
TrueStr=true
else
TrueStr=false
end if
end function

接著就可判斷後再做文件的上傳

if TrueStr(filename)=false then
response.write "非法文件"
response.end
end if

file.SaveAs Server.mappath(filename)

⑽ 簡單asp上傳文件代碼

我還是一點一點用一個實例來說明的吧,客戶端HTML如下。要瀏覽上傳附件,
我們通過<input type="file">元素,但是一定要注意必須設置form的enctype
屬性為"multipart/form-data":
<form method="post" action="upload.asp"
enctype="multipart/form-data">
<label>
<input type="file" name="file1" />
</label>

<input type="text" name="filename" value="default filename"/>

<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</form>
在後台asp程序中,以前獲取表單提交的ASCII 數據,非常的容易。但是如果
需要獲取上傳的文件,就必須使用Request對象的BinaryRead方法來讀取。Bin
aryRead方法是對當前輸入流進行指定位元組數的二進制讀取,有點需要注意的
是,一旦使用BinaryRead 方法後,再也不能使用Request.Form 或
Request.QueryString 集合了。結合Request對象的TotalBytes屬性,可以將
所有表單提交的數據全部變成二進制,不過這些數據都是經過編碼的。首先讓
我們來看看這些數據是如何編碼的,有無什麼規律可循,編段代碼,在代碼中
我們將BinaryRead讀取的二進制轉化為文本,輸出出來,在後台的upload.asp
中(注意該示例不要上傳大文件,否則可能會造成瀏覽器死掉):
<%
Dim biData, PostData
Size = Request.TotalBytes
biData = Request.BinaryRead(Size)
PostData = BinaryToString(biData,Size)
Response.Write "<pre>" & PostData & "</pre>" '使用pre,原樣輸出格式
' 藉助RecordSet將二進制流轉化成文本
Function BinaryToString(biData,Size)
Const adLongVarChar = 201
Set RS = createObject("ADODB.Recordset")
RS.Fields.Append "mBinary", adLongVarChar, Size
RS.Open
RS.AddNew
RS("mBinary").AppendChunk(biData)
RS.update
BinaryToString = RS("mBinary").Value
RS.Close
End Function
%>

熱點內容
光遇蘋果如何下載安卓服 發布:2024-04-20 13:40:03 瀏覽:460
半歲學編程 發布:2024-04-20 13:17:53 瀏覽:217
linux按鍵 發布:2024-04-20 13:17:52 瀏覽:832
最頂配的伺服器能容納多少ip 發布:2024-04-20 13:17:44 瀏覽:514
貸款車解壓需要什麼 發布:2024-04-20 13:14:52 瀏覽:72
安卓手機電腦怎麼切換 發布:2024-04-20 13:13:25 瀏覽:893
android交叉編譯環境 發布:2024-04-20 13:00:10 瀏覽:184
伺服器怎麼搭建中間層 發布:2024-04-20 12:40:02 瀏覽:98
如何獲取網路的賬號和密碼 發布:2024-04-20 12:34:06 瀏覽:921
安卓現在哪個品牌用得最久 發布:2024-04-20 12:00:50 瀏覽:278