asp上傳圖片組件
⑴ 我想用ASP上傳圖片,我用的是ASPUPLOAD組件,可惜伺服器不支持,怎麼樣才能實現無組件上傳
'文件的無組建上傳,如果上傳成功那麼返回上傳後的相對路徑。
Function FileUpLoad(FileFrom,FileGo)
Dim Postfix,FileName,UpLoadPath,Sobject
Postfix = LCase(Mid(FileFrom,InstrRev(FileFrom,".")))
If Postfix = ".jpg" or Postfix = ".gif" Then
FileName = Year(Now())&Month(Now())&Day(Now())&Hour(Now())&Minute(Now())&Second(Now())&Postfix
UpLoadPath = Server.MapPath(FileGo)&"\"&FileName
Set Sobject = Server.CreateObject("Adodb.Stream")
Sobject.Type = 1
Sobject.Open
Sobject.LoadFromFile FileFrom
Sobject.SaveToFile UpLoadPath,2
Sobject.Close
FileUpLoad = FileGo&"\"&FileName
Else
FileUpLoad = ""
End If
End Function
學ASP已經一年了,初學的時候感覺什麼都難,好幾次都想放棄,還好堅持了下來,今天看到有人要無組建上傳,我便隨便寫了個函數,希望大家給點意見
調用方法:
Call FileUpLoad("目標文件","把目標文件放在哪裡,這里是相對路徑,")
還是寫一下吧,
Dim fUd
fUd = Request.From("名字") '文件域
'你的根目錄下有一個Images的文件夾
Call FileUpLoad(fUd,"Images")
這樣就可以了。
⑵ ASP製作上傳圖片並顯示圖片
其實很簡單的啊!!不用想的那麼復雜!!
注(上傳時是需要組件的,無懼上傳組件不錯!)
首先,在你需要上傳圖片的頁面,引用上傳組件!
然後你再建一個處理頁面(也就是把圖片名稱,大小什麼的,存入資料庫的頁面,建議不要直接往資料庫里存圖片,那樣資料庫會非常龐大!只要把圖片上傳以後的路徑存到資料庫里就行)
最後就是顯示圖片了!!
給你簡要的說下,有不明白的地方加我QQ
⑶ 如何使用AspUpload組件上傳文件
你好,試試以下的方法:一、摘要Asp組件有內置的、伺服器安裝時附帶的,更多的是第三方提供的,今天來學習文件上傳的其中一個組件aspupload組件使用方法。
二、aspupload組件的下載、安裝或注冊 1、asp組件的下載、安裝
(1)可以從網上下載。
(2)直接雙擊後進行安裝。
AspUpload組件下載2、asp上傳組件的功能
a.限制上載文件的大小
b.設置用戶的許可權
c.修改文件屬性
d.同時上載多個文件
e.能夠將文件保存到資料庫中
f.支持文件刪除,自動生成與伺服器上文件不同名的文件
g.擁有管理許可權的用戶甚至可以使用該控制項進行遠程注冊
三、aspupload組件的簡單應用
1、實例一(1.asp):通過代碼實現三個文件的上傳功能。
如下圖所示:
(1)靜態頁面:1個表單,三個文件域,一個按鈕,其中表單form的動作如下。 (2)其中客戶端文件要注意幾點:
* 文件上載提交表單(Form)的enctype必須指定為「multipart/form-data」
* 語句表示上載文件域,用戶可以在該域中輸入或選定文件。
* 傳遞一個參數act(名稱可自己取),其值可以自己隨便定,目的是觸發上傳事件。
(3)動態代碼如下:
2、實例二(2.asp):修改程序1.asp,要求在上傳文件後顯示上傳文件的文件名及大小。
增加如下代碼: response.write("文件1是:
")response.write(upload.files(1).path)
response.write("文件2是:
")response.write(upload.files(2).path)
response.write("文件3是:
")
response.write(upload.files(3).path)
說明:
upload.files方法用來獲取文件的相關屬性,path是文件的路徑,size是文件的大小。
3、實例三(3.asp):修改程序2.asp,要求上傳的三個文件大小不能超過5K,如果上傳的文件已經存在則要求不覆蓋文件。
在上傳之前增加如下代碼:
upload.setmaxsize 5120,false
upload.overwritefiles=fals說明:
(1)upload.setmaxsize 5120,false其功能為設置文件最大為5120位元組,false參數說明當文件超過5120位元組時則刪除超過部分,true參數說明當文件超過5120位元組時則出錯。
(2)upload.overwritefiles=false,其功能表示文件不進行覆蓋,如果上傳同樣文件名的文件,上傳後文件名自動會在後面添加一個數字。
四、自學第二個上傳文件的組件
1、Lyfupload組件的下載
2、學習此組件的安裝或注冊
3、通過課本例子進行文件的上傳
五、問題
1、傳到學校里伺服器172.18.0.7運行時出現以下錯誤,Server.CreateObject 失敗
分析原因:學校伺服器不支持aspupload上傳組件
2、如果伺服器不支持aspupload等上傳組件,請大家使用無組件上傳功能(編寫代碼),見書本上P322,此類代碼比較復雜,同學們能夠拿來使用,無須自己編寫。
3、大家在網上申請個人空間時要看清伺服器支持哪些組件,這樣有利於編寫代碼。
⑷ ASP中上傳圖片怎麼做啊
採用無組件下載代碼。
upfile.asp
<% 'OPTION EXPLICIT%>
<!--#include FILE="upload_5xsoft.inc"-->
<%
dim upload,file,formName,formPath,iCount,MyFile
set upload=new upload_5xSoft ''建立上傳對象
formpath="userdata/" ''得到上傳目錄
nian=Year(Date)
yue=Month(Date)
ri=Day(Date)
if len(nian)<4 then nian="00"&nian
if len(yue)<2 then yue="0"&yue
if len(ri)<2 then ri="0"&ri
ipinit=""
ip=Request.ServerVariables("REMOTE_ADDR")
tmpip=Split(ip,".")
tmpipb=UBound(tmpip)
' ReDim ThisIP(tmpipb)
for i=0 to tmpipb
ThisIp=tmpip(i)
Do WHile len(ThisIP)<3
ThisIP="0"+ThisIP
loop
ipinit=ipinit+ThisIP
next
'Response.write nian&yue&ri&ipinit
'Response.end
for each formName in upload.file ''列出所有上傳了的文件
set file=upload.file(formName) ''生成一個文件對象
if file.FileSize>0 then ''如果 FileSize > 0 說明有文件數據
'MyFile=formPath&File.FileName
'MyFile=File.FileName
shi=Hour(time)
fen=Minute(Time)
Miao=Second(Time)
if len(shi)<2 then shi="0"&shi
if len(fen)<2 then fen="0"&fen
if len(miao)<2 then miao="0"&miao
MyFile=nian&yue&ri&shi&fen&miao&ipinit&".txt"
file.SaveAs Server.mappath(formPath&MyFile) ''保存文件
response.write file.FilePath&"#"&file.FileName&"#"&" ("&file.FileSize&") => "&MyFile&" 成功!<br>"
end if
set file=nothing
next
set upload=nothing ''刪除此對象
%>
upload_5xsoft.inc
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim upfile_5xSoft_Stream
Class upload_5xSoft
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="HTTP上傳程序 Version 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
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_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
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_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
⑸ asp如何實現圖片和視頻批量上傳
ASP批量上傳圖片代碼風聲無組件上傳類'上傳界面 up.asp<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!--#include file="../Connections/conn.asp" --><%
'主菜單
Dim zpmenurs
Dim zpmenurs_numRowsSet zpmenurs = Server.CreateObject("ADODB.Recordset")
zpmenurs.ActiveConnection = MM_conn_STRING
zpmenurs.Source = "SELECT * FROM menu_2 WHERE menu=3"
zpmenurs.CursorType = 0
zpmenurs.CursorLocation = 2
zpmenurs.LockType = 1
zpmenurs.Open()zpmenurs_numRows = 0
%><%'次級菜單
Dim zpchildrs
Dim zpchildrs_numRowsSet zpchildrs = Server.CreateObject("ADODB.Recordset")
zpchildrs.ActiveConnection = MM_conn_STRING
zpchildrs.Source = "SELECT * FROM menu_2child"
zpchildrs.CursorType = 0
zpchildrs.CursorLocation = 2
zpchildrs.LockType = 1
zpchildrs.Open()zpchildrs_numRows = 0
%>//連動菜單腳本 如果不做連動菜單可以刪除//////////////////////////////////////////-------------開始----------------------------------------------------------------------
<SCRIPT language=javascript1.2>
function showsubmenu(sid)
{
whichel = eval("submenu" + sid);
if (whichel.style.display == "none")
{
eval("submenu" + sid + ".style.display='';");
}
else
{
eval("submenu" + sid + ".style.display='none';");
}
}
</SCRIPT><SCRIPT language=JavaScript type=text/javascript>
<!--var arrDynaList = new Array();
var arrDL1 = new Array();arrDL1[1] = "mainmenu"; // Name of parent list box
arrDL1[2] = "picform1"; // Name of form containing parent list box
arrDL1[3] = "submenu"; // Name of child list box
arrDL1[4] = "picform1"; // Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, = "menu_father" // Name of recordset field relating to parent
txtDynaListLabel = "menu_child" // Name of recordset field for child Item Label
txtDynaListValue = "menu_child" // Name of recordset field for child Value
Set oDynaListRS = zpchildrs // Name of child list box recordset
Dim varDynaList
varDynaList = -1Dim varMaxWidth
varMaxWidth = "1"Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).ValueDim varCheckLength
varCheckLength = 0Dim varMaxLength
varMaxLength = 0While (NOT oDynaListRS.EOF)If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"
<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
WendIf (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>//-->
</SCRIPT><SCRIPT language=JavaScript type=text/javascript>
<!--
function setDynaList(arrDL){var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
var arrList = arrDL[5];
clearDynaList(oList2);
if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}
function clearDynaList(oList){for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
}
function populateDynaList(oList, nIndex, aArray){for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}if (oList.options.length == 0){
oList.options[oList.options.length] = new Option("[none available]",0);
}
oList.selectedIndex = 0;
}function Kermy_JS(jsStr) {
return eval(jsStr)
}function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</SCRIPT>-------------------------------連動菜單結束-----------------------------------//以下為上傳界面==============================================<TABLE borderColor=#0099ff height=80 cellSpacing=1 cellPadding=0 width="100%" bgColor=#0099ff border=0>
<TBODY>
<TR>
<TD vAlign=center align=left width="15%" bgColor=#ffffff height=37>選擇類型:</TD>
<TD vAlign=center align=left bgColor=#ffffff colSpan=2>添加具體項目:<SELECT id=mainmenu onchange="Kermy_JS('setDynaList(arrDL1)')" name=mainmenu ?> <OPTION value="<%=(zpmenurs.Fields.Item(" selected menu_father?).Value)%>"></OPTION></SELECT><SELECT id=submenu name=submenu></SELECT><% '上傳文件個數
num=1
if request.querystring("number")<>"" Then
num=Trim(request.querystring("number"))end if
%>上傳文件數 <SELECT onchange="MM_jumpMenu('parent',this,0)" name=menu1> <OPTION selected>== 請選擇==</OPTION> <OPTION value=?number=1>1</OPTION> <OPTION value="?number=<%=i%>"></OPTION></SELECT> <INPUT id=num type=hidden value="<%=num %>" name=num></TD></TR><%
for j=1 to num
%>
<TR>
<TD vAlign=center align=left bgColor=#ffffff>上傳圖片<%= j %>:</TD>
<TD vAlign=center align=left bgColor=#ffffff colSpan=2><INPUT id=pic style="WIDTH: 100px" type=file onchange=null.value=no name=pic> </TD></TR><% next %>
<TR>
<TD vAlign=center align=left bgColor=#ffffff> </TD>
<TD vAlign=center align=left bgColor=#ffffff colSpan=2><INPUT type=submit value=提交 name=Submit> <LABEL><INPUT type=reset value=重置 name=Submit2> </LABEL></TD></TR>
<TR>
<TD height=1></TD>
<TD width="34%"></TD>
<TD width="51%"></TD></TR></TBODY></TABLE><%
zpmenurs.Close()
Set zpmenurs = Nothing
%><%
zpchildrs.Close()
Set zpchildrs = Nothing
%>up.asp 結束
⑹ asp中上傳圖片的組件,
4個文件實現無組件上傳4個文件實現無組件上傳
嵌套式調用:
<iframe name="ad" frameborder=0 width=100% height=50 scrolling=no src=uploada.asp></iframe>
直接鏈接:uploada.asp
文件保存路徑:upload
上傳文件類型和大小自己設置
===========================================
第一個文件:inc/confing.asp(inc為文件夾名稱)
<%
Const EnableUploadFile="Yes" '是否開放文件上傳
Const MaxFileSize=200 '上傳文件大小限制
Const UpFileType="gif|jpg|bmp|png|swf|doc|txt|rar|zip" '允許的上傳文件類型
%>
===========================================
第二個文件:inc/upload.asp
dim oUpFileStream
Class upload_file
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.96"
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)
oUpFileStream.Position=0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = chrB(13) & chrB(10)
'取得每個項目之間的分隔符
sStart = MidB(RequestBinDate‚1‚ InStrB(1‚RequestBinDate‚bCrLf)-1)
iStart = LenB (sStart)
iFormStart = iStart+2
'分解項目
Do
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
'取得表單項目名稱
iFormStart = InStrB(iInfoEnd‚RequestBinDate‚sStart)-1
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)
oFileInfo.FileExt = GetFileExt(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 -2
oFileInfo.FormName = sFormName
file.add sFormName‚oFileInfo
else
'如果是表單項目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream‚iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.Charset = "gb2312"
sFormvalue = tStream.ReadText
form.Add sFormName‚sFormvalue
end if
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
loop until (iFormStart+2) = iFormEnd
RequestBinDate=""
set tStream = nothing
End Sub
Private Sub Class_Terminate
'清除變數及對像
if not Request.TotalBytes<1 then
oUpFileStream.Close
set oUpFileStream =nothing
end if
Form.RemoveAll
File.RemoveAll
set Form=nothing
set File=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 GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath‚InStrRev(FullPath‚ ".")+1)
Else
GetFileExt = ""
End If
End function
End Class
'文件屬性類
Class FileInfo
dim FormName‚FileName‚FilePath‚FileSize‚FileType‚FileStart‚FileExt
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
'保存文件方法
Public function SaveToFile(FullPath)
dim oFileStream‚ErrorChar‚i
SaveToFile=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.to oFileStream‚FileSize
oFileStream.SaveToFile FullPath‚2
oFileStream.Close
set oFileStream=nothing
SaveToFile=0
end function
End Class
%>
========================================
第三個文件:uploada.asp
<!--#include file="Inc/config.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #f5feed;
font-size:9pt
}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
<link href="Manage/Inc/ManageMent.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0">
<%
if EnableUploadFile="Yes" then
%>
<form action="upfilea.asp" method="post" name="form1" enctype="multipart/form-data">
<input name="FileName" type="FILE" class="tx1" size="20">
<input type="submit" name="Submit" value="上傳" style="border:1px double rgb(88‚88‚88);font:9pt">
</form>
<%
end if
%>
</body>
</html>
============================
第四個文件:upfilea.asp
<!--#include file="Inc/config.asp"-->
<!--#include file="Inc/upload.asp"-->
<%
const upload_type=0 '上傳方法:0=無懼無組件上傳類,1=FSO上傳 2=lyfupload,3=aspupload,4=chinaaspupload
dim upload‚file‚formName‚SavePath‚filename‚fileExt
dim upNum
dim EnableUpload
dim Forumupload
dim ranNum
dim uploadfiletype
dim msg‚founderr
msg=""
founderr=false
EnableUpload=false
SavePath = "Upload" '存放上傳文件的目錄
if right(SavePath‚1)<>"/" then SavePath=SavePath&"/" '在目錄後加(/)
%>
<%
ComeinSTR=lcase(request.servervariables("HTTP_HOST"))
Url=split(ComeinSTR)
yourthing=Url(0)
%>
<html>
<head>
<link href="Manage/Inc/ManageMent.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
if EnableUploadFile="NO" then
response.write "系統未開放文件上傳功能"
else
select case upload_type
case 0
call upload_0() '使用化境無組件上傳類
case else
end select
end if
%>
</body>
</html>
<%
sub upload_0() '使用化境無組件上傳類
set upload=new upload_file '建立上傳對象
for each formName in upload.file '列出所有上傳了的文件
set file=upload.file(formName) '生成一個文件對象
if file.filesize<100 then
msg="請先選擇你要上傳的文件!"
founderr=true
end if
if file.filesize>(MaxFileSize*1024) then
msg="文件大小超過了限制,最大隻能上傳" & CStr(MaxFileSize) & "K的文件!"
founderr=true
end if
fileExt=lcase(file.FileExt)
Forumupload=split(UpFileType‚"|")
for i=0 to ubound(Forumupload)
if fileEXT=trim(Forumupload(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
'msg="這種文件類型不允許上傳!\n\n只允許上傳這幾種文件類型:" & UpFileType
response.write"<script language=javascript>alert('這種文件類型不允許上傳!\n\n只允許上傳這幾種文件類型:" &
UpFileType & "');"
response.write"javascript:history.go(-1)</script>"
founderr=true
end if
strJS="<script language=javascript>" & vbcrlf
if founderr<>true then
randomize
ranNum=int(900*rnd)+100
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
file.SaveToFile Server.mappath(FileName) '保存文件
msg="上傳文件成功!"
FileType=right(fileExt‚3)
select case FileType
case "jpg"‚"gif"‚"png"‚"bmp"
case "swf"
case else
strJS=strJS & "range.text=' 點擊瀏覽該文件';" & vbcrlf
end select
end if
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "</script>"
response.write strJS
response.write "圖片上傳成功!文件路徑是 /" & filename & "<br>"
response.write "http://";; & yourthing & "/" & filename & "<br>"
set file=nothing
next
set upload=nothing
end sub
%>
⑺ asp里,上傳圖片,是有組件好,還是不用組件好
我覺得用組件上傳速度快些,穩定些,但需要在伺服器上安裝組件,如果你對伺服器沒有操作許可權就行不通。無組件上傳就不需要伺服器的支持,只要上傳的目錄有寫入許可權就行。