asp_databases thread: how to insert image and table into database using asp program?
Anybody know how to insert images and table into a database by using asp
program ?
Actually I have a program where user will key-in information about them into
my web site. They also will insert a picture and also some data and info
about them.Maybe they want it to be colourful and more.But my program only
receive text data because I used textarea to collect that information.
Maybe I should use another type that can include text + picture+ table in
that form.......
Please help me !!!
Here's a sub I wrote in VB that inserts images it
finds in directories called "large" and "thumbs" on a
fileserver on our network. I'm inserting into a Long
Raw column in Oracle. I originally found the usage of
the ADO AppendChunk on ASPToday (I think).
Here's the code - sorry for the long post..
Craig shields
Private Sub Command2_Click()
Dim PictBmp As String
Dim ByteData() As Byte 'Byte array for Blob
data.
Dim SourceFile As Integer
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
Dim rs4 As New ADODB.Recordset
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim FSO2 As FileSystemObject
Dim Folder
Dim files
Dim tmpFile
Dim tmpFileDel
Dim tmpExt
Dim tmpLen
Dim f1
Dim a As Integer
Dim vFolder As String
Dim vExt As String
Dim vPath
Dim vNewFolder
Dim StrName
Dim LineNum
'On Error GoTo Image_Error
Set FSO2 = New FileSystemObject
LineNum = 0
a = 0
StrName = "\\IMAGE\WEBIMAGE\BACKUPS\BACKUP_" &
Replace(FormatDateTime(Now, 2), "/", "_")
If Not FSO2.FolderExists(StrName) Then
Set vNewFolder = FSO2.CreateFolder(StrName)
Else
vNewFolder = FSO2.GetFolder(StrName)
End If
LineNum = 1
Do While Not a = 2
Select Case a
Case 0
vFolder = "LARGE"
vExt = ".jpg"
Case 1
vFolder = "THUMBS"
vExt = ".gif"
End Select
LineNum = 2
Set Cn = New ADODB.Connection
Cn.Open "Provider=xxxxxxxxx"
LineNum = 3
Set Folder
FSO2.GetFolder("\\IMAGE\WEBIMAGE\" & vFolder)
LineNum = 4
FSO2.CopyFolder "\\IMAGE\WEBIMAGE\*" &
vFolder, vNewFolder, True
LineNum = 5
Set files = Folder.files
LineNum = 6
If Not IsEmpty(files) Then
For Each f1 In files
tmpLen = Len(f1.Name)
tmpFile = Left(f1.Name, (tmpLen - 4))
tmpExt = Right(f1.Name, 4)
strSQL3 = "select product_id from blob
where " & _
"product_id = '" &
UCase(tmpFile) & "' " & _
"and blob_type = '" & vExt &
"'"
Set rs3 = New ADODB.Recordset
rs3.CursorType = adOpenKeyset
rs3.LockType = adLockOptimistic
rs3.Open strSQL3, Cn
If rs3.EOF = True Then
' Create new row for BLOB
strSQL2 = "insert into blob
(product_id, blob_type) " & _
"values ('" &
UCase(tmpFile) & "', '" & vExt & "')"
Set rs2 = New ADODB.Recordset
rs2.CursorType = adOpenKeyset
rs2.LockType = adLockOptimistic
rs2.Open strSQL2, Cn
If
rs2.ActiveConnection.Errors(0).Number <> 0 Then
'If Cn.Errors.Count <> 0 Or
Err.Number <> 0 Then
Dim tmpath
tmpath = "\\IMAGE\WEBIMAGE\" &
vFolder & "\" & f1.Name
FSO2.MoveFile tmpath,
"\\IMAGE\WEBIMAGE\" & vFolder & "\BAD\" & f1.Name
Exit For
End If
End If
strSQL = "Select blob_data from blob
" & _
"WHERE product_id = '" &
UCase(tmpFile) & "' " & _
"and blob_type = '" & vExt
& "'"
Set Rs = New ADODB.Recordset
Rs.CursorLocation = 3
Rs.CursorType = 3
Rs.LockType = adLockOptimistic
Rs.Open strSQL, Cn
' Retrieve the picture and update
the record.
PictBmp = f1
' Save Picture image to the table
column.
SourceFile = FreeFile
Open PictBmp For Binary Access Read
As SourceFile
FileLength = LOF(SourceFile) ' Get
the length of the file.
Dim lngOffSet
If FileLength = 0 Then
Close SourceFile
GoTo Image_Error
Else
lngOffSet = 0
Numblocks = FileLength /
BlockSize
LeftOver = FileLength Mod
BlockSize
ReDim ByteData(LeftOver)
Get SourceFile, , ByteData()
Rs(0).AppendChunk ByteData()
ReDim ByteData(BlockSize)
For i = 1 To Numblocks
Get SourceFile, , ByteData()
Rs(0).AppendChunk ByteData()
Next i
Rs.Update 'Commit the new
data.
Close SourceFile
Set rs2 = Nothing
End If
'End If
Set rs3 = Nothing
Set Rs = Nothing
Set tmpFileDel
FSO2.GetFile("\\IMAGE\WEBIMAGE\" & vFolder & "\" &
f1.Name)
tmpFileDel.Delete
UpdateSku UCase(Trim(tmpFile))
Next
End If
'Set FSO3 = Nothing
Set Folder = Nothing
Set files = Nothing
Set Cn = Nothing
a = a + 1
Loop
Set FSO2 = Nothing
Set vNewFolder = Nothing
Exit Sub
Image_Error:
Err.Raise Err.Number, Err.Source,
Err.Description & "strSQL2 = " & strSQL2
Dim LogFile
Dim FSO4 As FileSystemObject
Set FSO4 = New FileSystemObject
Set LogFile
FSO4.OpenTextFile("\\image\webimage\DOC\ImageErr_log.txt",
8, True)
LogFile.WriteLine Now & " - " & Err.Number & " -
" & Err.Description & " linenumber: " & LineNum '& " "
& f1.Name
LogFile.Close
Set Rs = Nothing
Set rs2 = Nothing
Set rs3 = Nothing
Set LogFile = Nothing
Set FSO4 = Nothing
'Resume Next
End Sub
--- Lizawati Bakri <LIZA_B@e...> wrote:
> Anybody know how to insert images and table into a
> database by using asp
> program ?
>
> Actually I have a program where user will key-in
> information about them into
> my web site. They also will insert a picture and
> also some data and info
> about them.Maybe they want it to be colourful and
> more.But my program only
> receive text data because I used textarea to collect
> that information.
> Maybe I should use another type that can include
> text + picture+ table in
> that form.......
>
> Please help me !!!
>
>
> ---
> Please take a moment to tell us how you are using
> AuthentiX, WebQuota, and
> VideoQuota
>
> http://www.flicks.com/feedback/feed.asp
>
> Scott Gordon
> Marketing
> Flicks Software
> www.flicks.com
> xxx-xxx-xxxx
> cmshields@k...
> $subst('Email.Unsub')
>
>
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/