當前位置:編程學習大全網 - 源碼下載 - 求壹個能上傳小說和圖片的網站源碼

求壹個能上傳小說和圖片的網站源碼

這是我用的asp的,圖片存在UpImages文件下,圖片文件存在數庫裏,別外妳自添加數據連接吧;

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " All Rights Reserved.<br />

版權所有: | 技術支持:<a href="mailto:yaoyaovip@yahoo.com.cn">書叢</a> | 渝ICP備000**0號 </span></th>

</tr>

</table>

<%

if request("action") = "Addnew" then

newline = chrB(13) & chrB(10) 'newline表示二進制的回車符

filesize = Request.TotalBytes 'filesize是表單數據大小

filedata = Request.BinaryRead(filesize) 'filedata是表單的二進制數據

divider = leftB(filedata,clng(instrb(filedata,newline))-1) 'divider是分割符

Set Rs = Server.CreateObject("ADODB.RecordSet")

Sql="Select * From word"

Rs.Open Sql,conn,3,3

Rs.addnew

k = 1

While instrb(k,filedata,divider) < instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)

start = instrb(k,filedata,divider) + lenb(divider) +2

endsize = instrb((instrb(k,filedata,divider) + lenb(divider)),filedata,divider) - start - 2

content = midb(filedata,start,endsize) '取文件說明部分

start_name = instrb(content,toByte("name="""))

end_name = instrb(start_name + 6,content,toByte(""""))

nametag = midb(content,start_name+6,end_name-start_name-6) '取文件說明部分中name=""中的內容,即表單元素的名稱

pos1_filename = instrb(end_name,content,toByte("filename="""))

'如果是文件框,則文件說明部分應有filename="",那麽pos1_filename不等於0

If pos1_filename = 0 Then '表單中不屬於文件上傳的數據處理

namevalue = toStr(midb(content,end_name+5,lenb(content)-end_name-4)) '取文件內容

' 將文件說明部分的name=""中的內容與表單元素的名稱進行比較,把相應的內容加入數據庫

If(InStr(toStr(nametag),"file") > 0)Then 'CenterID2'為表單控件的name屬性值,以下同

Rs("image") = namevalue

session("CenterID") = namevalue '用於上傳文件保存時的文件名中

End If

If(InStr(toStr(nametag),"title") > 0)Then

Rs("title") = namevalue

if namevalue="" then

Response.Write "<Script>alert('請輸入標題!')</Script>"

response.end

end if

End If

If(InStr(toStr(nametag),"content") > 0)Then

Rs("content") = namevalue

if namevalue="" then

Response.Write "<Script>alert('請輸入內容!')</Script>"

response.end

end if

End If

If(InStr(toStr(nametag),"select") > 0)Then

Set Rs1 = Server.CreateObject("ADODB.RecordSet")

Sql="Select * From mun"

Rs1.Open Sql,conn,3,3

Rs1("mun")=namevalue

Rs1.update

Rs1.Close

Set Rs1=nothing

End If

Rs("wtime") = year(now)&"-"&month(now)&"-"&day(now)

'Response.Write (namevalue)

'Response.Write(" <br>")

else '處理文件上傳部分的數據

pos2_filename = instrb(pos1_filename+10,content,toByte(""""))

fullpath = midb(content,pos1_filename+10,pos2_filename-pos1_filename-10) '從文件說明部分中取出文件路徑

covername=GetFileName(toStr(fullpath))

If(fullpath <> "")Then '如果有上傳的文件,執行以下代碼

dim bStart ' 取二進制流文件部分開始位置

bStart = instrb(start,filedata,newline&newline)+3

dim bEnd ' 取二進制流文件部分結束位置

bEnd=inStrB(bStart+6,filedata,divider)-bStart-3

dim stm ' 定義壹個 adodb.stream 源對象 stm, 用以拷貝二進制流文件部分至另壹 adodb.stream fromStm

set stm=createObject("adodb.stream")

stm.type=1 ' 二進制模式

stm.mode=3 ' 指定打開模式為讀寫

stm.open

stm.write filedata '寫入二進制流內容

dim fromStm '定義 adodb.stream 對象 fromStm, 以保存文件

set fromStm=createOBject("adodb.stream")

with fromStm

.type=1

.mode=3

.open

stm.position = bStart ' 指定 stm 對象的起始位置, 以變量 bStart 的值為起始位置

stm.copyTo fromStm, bEnd ' 拷貝 stm 二進制流至 fromStm 對象, 長度為 bEnd 變量的長度

.saveTofile server.MapPath (covername),2' 保存文件, 如果存在相同名稱, 則覆蓋

.close

end with

set fromStm = nothing

stm.close

set stm = nothing

Rs("image") =covername '將文件的相對路徑寫入數據庫中

end if

end if

k = instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)

Wend

Rs.update

Rs.close

set Rs = nothing

response.Redirect"mylife.asp"

end if

function toStr(Byt) '將二進制轉換為字符串

toStr=""

for i=1 to lenb(byt)

blow = midb(byt,i,1)

if ascb(blow)>127 then

toStr = toStr&chr(ascw(midb(byt,i+1,1)&blow)) '

i = i+1

else

toStr = toStr&chr(ascb(blow))

end if

Next

End function

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

Function GetFileName(imagespath)'將路徑轉換為時間,並使上傳的文件不重名

If imagespath <> "" Then

rname=right(toStr(fullpath),len(toStr(fullpath))-InStrRev(toStr(fullpath),".")+1)'獲得後綴名

GetFileName = "UpImages/" & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rname

Else

GetFileName =""

End If

End Function

%>

</body>

</html>

  • 上一篇:HTTP 錯誤 500.100 - 內部服務器錯誤 - ASP 錯誤
  • 下一篇:什麽是期貨?什麽是期權?
  • copyright 2024編程學習大全網