เราเขียน program ASP ไม่ได้อ่ะที่ save ภาพ ไฟล์ หรือว่า ไฟล์รูปภาพอ่ะ ลงในdatabase ไม่ได้
มัน error ใครcode ได้ บอกเราหน่อยสิ หรือว่าถ้าcode เสร็จภายใน 2วันได้เราจะจ้าง
add mail เราไว้ได้ จะได้คุยกันค่ะ [email protected] เราจะส่งวันที่ 2แล้วอ่ะ
ใครช่วยได้ตอนนี้เราอยู่ปทุม เราต้องการความช่วยเหลือตอนนี้เลย หน้าล่ะเท่าไหร่คงไม่แพงนะ
อือ ช่วยหน่อยนะค่ะถ้าใครอ่านแล้ว หรือมีเพือน codeได้อยากได้ตังค์ ถ้าคุยรู้เรื่องแล้วเราจะโทร
ให้ช่วย
ขอบคุณค่ะ
Tag : - - - -
Date :
25 ก.พ. 2548 12:48:57
By :
เล็กน้อย
View :
2743
Reply :
3
No. 1
Guest
******************************
up_to_dbase_example.asp < send to database>
******************************
<%
response.buffer = true
Dim Uploader, File
Set Uploader = New FileUploader
Uploader.Upload()
Response.Write "<b>การส่งข้อมูลเสร็จสมบูรณ์" & Uploader.Form("fullname") & "</b><br>"
' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
Response.Write "ไม่สามารถส่งข้อมูลได้เนื่องจากข้อมูลไม่มีการเลือกรูปภาพ"
Else
' Loop through the uploaded files
For Each File In Uploader.Files.Items
Dim RS,Con,Cstring,sql,MYMESSAGE,i,j
CString = "DBQ=" & Server.Mappath("../database/News.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
Set CON = server.CreateObject("adodb.connection")
Con.open Cstring
Set RS = Server.CreateObject("ADODB.Recordset")
SQL= "SELECT filename, filesize, contenttype, filedata, fullname, EMAIL, Head, story, News, D, t from Activity"
RS.Open SQL,con,2,3
RS.AddNew
RS("filename") = File.FileName
RS("filesize") = File.FileSize
RS("contenttype") = File.ContentType
RS("FULLNAME") = Uploader.Form("fullname")
RS("EMAIL") = Uploader.Form("EMAIL")
RS("Head") = Uploader.Form("Head")
RS("story") = Uploader.Form("story")
RS("News") = Uploader.Form("News")
RS("D") = DATE
RS("T") = TIME
' Save the file to the database
File.SaveToDatabase RS("filedata")
' Commit the changes and close
RS.Update
RS.Close
' Output the file details to the browser
'here I added a redirect to the display page
response.write "Uploading file: " & File.FileName & "<br>"
response.flush
'process logic here, for testing
for i = 0 to 100000
for j = 0 to 20
next
next
response.write "Done processing, sending you after 3sec to the display page<br>"
Response.Write "File Uploaded : &bsp" & File.FileName & "<br>"
Response.Write "Size : &bsp" & File.FileSize & " bytes<br>"
Response.Write "Type : &bsp " & File.ContentType & "<br>"
response.flush
Next
End If
%>
*****************************
Configurations.asp
*****************************
<%
Dim ID
ID = Request.QueryString("ID")
Dim Conn, RS, SQL
SQL = "SELECT filedata FROM Activity WHERE ID = " & ID
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DBQ=" & Server.Mappath("../database/News.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQL, Conn
Response.ContentType = "image/jpg"
Response.BinaryWrite RS("filedata")
RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
%>
*************************
<%
Class FileUploader
Public Files
Private mcolFormElem
Private Sub Class_Initialize()
Set Files = Server.CreateObject("Scripting.Dictionary")
Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll()
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll()
Set mcolFormElem = Nothing
End If
End Sub
Public Property Get Form(sIndex)
Form = ""
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
'String to byte string conversion
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
'Byte string to string conversion
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub
If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub