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

asp文件上傳代碼

發布時間: 2025-04-07 05:52:00

『壹』 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.net 2.0中如何實現上傳文件與下載文件 用啥控制項和代碼啊

需用到FileUpLoad控制項
#region 文件上傳
/*
if (FileUpload1.HasFile)
{
string type = FileUpload1.PostedFile.ContentType.ToString();
if (type == "image/pjpeg")
{
string path = Server.MapPath("up/");
FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName);
Response.Write("<script>alert('上傳成功!');</script>");
}
else
Response.Write("<script>alert('請上傳獲得支持的文件類型!');</script>");

}
else
Response.Write("<script>alert('請選擇您要上傳的文件!');</script>");
//*/

『叄』 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>

(3)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源碼:上傳文件大小限定,圖片尺寸自動調整

分類: 電腦/網路 >> 程序設計 >> 其他編程語言
問題描述:

網上搜的多而且雜,越看越迷糊..........

最好把每頁的代碼都寫一下,大致兩三個頁就可以解決了,謝謝達人幫助!!!!!!

解析:

三個頁:選擇頁,上傳頁sub,調用的代碼頁upload.inc,

我自己就在用這個,LZ給分吧

1瀏覽上傳:

<form action="sub" method="post" enctype="multipart/form-data" target="_self">

<input type=file name=src size="20" value="瀏覽">

<input type=submit value="上傳" name=B1 IsShowProcessBar="True">

</form>

sub 執行上傳並返回地址,同時保存文件名在session(ccc)中

<!--#include FILE="upload.inc"-->

<%

dim upload,file,formName,formPath,iCount,fileformat

set upload=new upload_F

function MakedownName()

dim fname

fname = now()

fname = replace(fname,"-","")

fname = replace(fname," ","")

fname = replace(fname,":","")

fname = replace(fname,"PM","")

fname = replace(fname,"AM","")

fname = replace(fname,"上午","")

fname = replace(fname,"下午","")

fname = int(fname) + int((10-1+1)*Rnd + 1)

MakedownName=fname

end function

formPath="upload/"

iCount=0

for each formName in upload.file ''列出所有上傳了的文件

set file=upload.file(formName) ''生成一個文件對象

fileformat=lcase(right(file.filename,4))

if fileformat="" or fileformat="" then

response.write"<script>alert('文件格式不對,請重新上傳!');location='"&request.ServerVariables("HTTP_REFERER")&"'</script>"

response.end

end if

if file.FileSize>0 then ''如果 FileSize > 0 說明有文件數據

newname=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)

session("ccc")=newname

file.SaveAs Server.mappath(formPath&newname) ''保存文件

iCount=iCount+1

else

response.write "<font style=FONT-SIZE:9pt>未找到文件 <A HREF=javascript:history.back(1)>重新上傳</A><font style=FONT-SIZE:9pt>"

response.end

end if

next

%>

<%

response.write "<a href='upload/"&newname&"' target=_blank>upload/"&newname&" </a>("&cint(file.FileSize/1024)&"K) 上傳成功!"

%>

<%

set file=nothing

set upload=nothing ''刪除此對象

%>

upload.inc 頁的代碼如下:

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_Stream

Class upload_F

dim Form,File,Version

Private Sub Class_Initialize

dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile

dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr

Version="upload Version 1.0"

if Request.TotalBytes<1 then Exit Sub

set Form=CreateObject("Scripting.Dictionary")

set File=CreateObject("Scripting.Dictionary")

set upfile_Stream=CreateObject("Adodb.Stream")

upfile_Stream.mode=3

upfile_Stream.type=1

upfile_Stream.open

upfile_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

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

form.Add mFormName,mFormValue

end if

iFormStart=iformEnd+iDivLen

iFormEnd=inString(iformStart,strDiv)-1

wend

End Sub

Private Function subString(theStart,theLen)

dim i,c,stemp

upfile_Stream.Position=theStart-1

stemp=""

for i=1 to theLen

if upfile_Stream.EOS then Exit for

c=ascB(upfile_Stream.Read(1))

If c > 127 Then

if upfile_Stream.EOS then Exit for

stemp=stemp&Chr(AscW(ChrB(AscB(upfile_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_Stream.Size-theLen

if i>upfile_Stream.size then exit Function

upfile_Stream.Position=i-1

if AscB(upfile_Stream.Read(1))=AscB(midB(Str,1)) then

InString=i

for j=2 to theLen

if upfile_Stream.EOS then

inString=0

Exit for

end if

if AscB(upfile_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_Stream.close

set upfile_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

End Class

Class FileInfo

dim FormName,FileName,FilePath,FileSize,FileStart

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_Stream.position=FileStart-1

upfile_Stream.to dr,FileSize

dr.SaveToFile FullPath,2

dr.Close

set dr=nothing

SaveAs=0

end function

End Class

</SCRIPT>

熱點內容
伺服器python 發布:2025-04-09 09:48:09 瀏覽:560
壓縮袋抽多久 發布:2025-04-09 09:45:53 瀏覽:161
phpqq分享 發布:2025-04-09 09:02:45 瀏覽:353
sql虛擬列 發布:2025-04-09 08:59:36 瀏覽:84
ps入門筆記本電腦需要什麼配置 發布:2025-04-09 08:56:34 瀏覽:277
abaqus需要什麼配置 發布:2025-04-09 08:53:09 瀏覽:734
vba查詢文件夾 發布:2025-04-09 08:51:38 瀏覽:447
圖的存儲與遍歷 發布:2025-04-09 08:50:39 瀏覽:61
拉桿箱的密碼鎖忘記密碼了怎麼辦 發布:2025-04-09 08:30:54 瀏覽:363
手機腳本助手 發布:2025-04-09 08:30:53 瀏覽:461