gud morning!!!!!!!!
i have a problem on how to upload photo and save it in the database....
i am not so familiar in visual basic on how to code.....
can you help me with this problem??
i want the codes that can the uploading and saving photos in visual basics....
tnx
slapshock
4 13725
To add a new record, the program lets the user select a graphic file. The program opens the file and reads it in blocks of binary data. For each block, the program uses AppendChunk to add the block to the database -
-
Private Sub mnuRecordAdd_Click()
-
Dim rs As ADODB.Recordset
-
Dim person_name As String
-
Dim file_num As String
-
Dim file_length As String
-
Dim bytes() As Byte
-
Dim num_blocks As Long
-
Dim left_over As Long
-
Dim block_num As Long
-
-
person_name = InputBox("Name")
-
If Len(person_name) = 0 Then Exit Sub
-
-
dlgPicture.Flags = _
-
cdlOFNFileMustExist Or _
-
cdlOFNHideReadOnly Or _
-
cdlOFNExplorer
-
dlgPicture.CancelError = True
-
dlgPicture.Filter = "Graphics " & _
-
"Files|*.bmp;*.ico;*.jpg;*.gif"
-
-
On Error Resume Next
-
dlgPicture.ShowOpen
-
If Err.Number = cdlCancel Then
-
Exit Sub
-
ElseIf Err.Number <> 0 Then
-
MsgBox "Error " & Format$(Err.Number) & _
-
" selecting file." & vbCrLf & Err.Description
-
Exit Sub
-
End If
-
-
' Open the picture file.
-
file_num = FreeFile
-
Open dlgPicture.FileName For Binary Access Read As _
-
#file_num
-
-
file_length = LOF(file_num)
-
If file_length > 0 Then
-
num_blocks = file_length / BLOCK_SIZE
-
left_over = file_length Mod BLOCK_SIZE
-
-
Set rs = New ADODB.Recordset
-
rs.CursorType = adOpenKeyset
-
rs.LockType = adLockOptimistic
-
rs.Open "Select Name, Picture, FileLength FROM " & _
-
"People", m_DBConn
-
-
rs.AddNew
-
rs!Name = person_name
-
rs!FileLength = file_length
-
-
ReDim bytes(BLOCK_SIZE)
-
For block_num = 1 To num_blocks
-
Get #file_num, , bytes()
-
rs!Picture.AppendChunk bytes()
-
Next block_num
-
-
If left_over > 0 Then
-
ReDim bytes(left_over)
-
Get #file_num, , bytes()
-
rs!Picture.AppendChunk bytes()
-
End If
-
-
rs.Update
-
Close #file_num
-
-
lstPeople.AddItem person_name
-
lstPeople.Text = person_name
-
End If
-
End Sub
-
To retreive a picture, the program selects the appropriate database record. It uses the TemporaryFileName function to get a temporary file name and opens the file. It then uses GetChunk to read the data from the database in blocks and writes the blocks into the file. The program then uses LoadPicture to load the file, and Kill to remove it. -
' Display the clicked person.
-
Private Sub lstPeople_Click()
-
Dim rs As ADODB.Recordset
-
Dim bytes() As Byte
-
Dim file_name As String
-
Dim file_num As Integer
-
Dim file_length As Long
-
Dim num_blocks As Long
-
Dim left_over As Long
-
Dim block_num As Long
-
Dim hgt As Single
-
-
picPerson.Visible = False
-
Screen.MousePointer = vbHourglass
-
DoEvents
-
-
' Get the record.
-
Set rs = m_DBConn.Execute("SELECT * FROM People WHERE " & _
-
"Name='" & _
-
lstPeople.Text & "'", , adCmdText)
-
If rs.EOF Then Exit Sub
-
-
' Get a temporary file name.
-
file_name = TemporaryFileName()
-
-
' Open the file.
-
file_num = FreeFile
-
Open file_name For Binary As #file_num
-
-
' Copy the data into the file.
-
file_length = rs!FileLength
-
num_blocks = file_length / BLOCK_SIZE
-
left_over = file_length Mod BLOCK_SIZE
-
-
For block_num = 1 To num_blocks
-
bytes() = rs!Picture.GetChunk(BLOCK_SIZE)
-
Put #file_num, , bytes()
-
Next block_num
-
-
If left_over > 0 Then
-
bytes() = rs!Picture.GetChunk(left_over)
-
Put #file_num, , bytes()
-
End If
-
-
Close #file_num
-
-
' Display the picture file.
-
picPerson.Picture = LoadPicture(file_name)
-
picPerson.Visible = True
-
-
Width = picPerson.Left + picPerson.Width + Width - _
-
ScaleWidth
-
hgt = picPerson.Top + picPerson.Height + Height - _
-
ScaleHeight
-
If hgt < 1440 Then hgt = 1440
-
Height = hgt
-
-
Kill file_name
-
Screen.MousePointer = vbDefault
-
End Sub
-
-
' Return a temporary file name.
-
Private Function TemporaryFileName() As String
-
Dim temp_path As String
-
Dim temp_file As String
-
Dim length As Long
-
-
' Get the temporary file path.
-
temp_path = Space$(MAX_PATH)
-
length = GetTempPath(MAX_PATH, temp_path)
-
temp_path = Left$(temp_path, length)
-
-
' Get the file name.
-
temp_file = Space$(MAX_PATH)
-
GetTempFileName temp_path, "per", 0, temp_file
-
TemporaryFileName = Left$(temp_file, InStr(temp_file, _
-
Chr$(0)) - 1)
-
End Function
thanks a lot! it will really help me a lot...
salamat!!! - slapshock
help me guys how to upload photo in vb6..please i nid in my thesis if you have a sample program please send to my email here my email mail id removed thanks to all..godbless
@Rowelle
have you tried the code posted in this thread ?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jmev7 |
last post by:
Is there a script that will allow upload of multiple images at once to
a FTP server, and simultaneously write that list to a MySQL table? I
need to allow users to do something like this.
Thanks.
|
by: Atz |
last post by:
Hi to all !
This is the working, completed PHP script for file upload.
The only problem is: wenn i send file and when the file is upload on the
server, the
file name ( orginal file name is...
|
by: matt |
last post by:
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt...
|
by: bob garbados |
last post by:
I am trying to create a database-driven photo gallery for a friend with an
admin form to upload images... I can upload a file to the web server, but I
want to store the image in a database and I...
|
by: Nicole Legroe |
last post by:
I have an asp.NET site running. I want to make it possible in my webpage, to
enter the name of an imagefile on my computer and to upload this file on my
webserver. What is the code to make this...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most...
|
by: owz2008 |
last post by:
This has probably been covered before but could not find a similar thread.
Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html
I want to submit the...
|
by: GuangXiN |
last post by:
I want the file upload element disappear, instead of it, I place a text
box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php"...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |