[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

Pulling GIF images from an Access Database

I want to create an employee database that has info like name, extension, email, etc and a picture (gif) of the the employee.  I know how to pull text from my Access database but I don't know how to pull images.  Does anyone know of any tutorials out there that could help?  Or maybe some past experiences?
0
dgwest
Asked:
dgwest
  • 3
  • 3
  • 2
  • +2
1 Solution
 
PBallCommented:
I think this topic has come up a lot of times before.

My suggestion, as many might have suggested before, is to keep the image outside of the database and store a pointer (filename) to the image files instead.
0
 
NickRackhamCommented:
dgwest

Check out my previous question http://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=10236282 

I asked exactly the same question a week or so back. Should resolve your problem.

As PBall stated above, don't try to get the imager from access but hold the images in your web in a folder called "photos" for want of a better example. then insert a column called photos in you data base and (If yor photo is called abc.gif) then enter abc in the record it relates to and have the asp page call the record write abc and then write .gif

I won't copy and paste another experts answer so check out the PAQ and all it'll cost you is 10 points.

Can't say fairer than that.

Regards

Nick
0
 
mgfranzCommented:
You can use three approaches to deliver the image from the database to the browser. The first way is to keep the image file on the hard drive, and store the file's name and path in the database. I don't recommend this approach, because putting the image file and its path in two different locations causes management problems. For example, if you change the filename, you must change the data entry in the database for its associated path. The second approach is to use the ASP Response object's BinaryWrite method. This method passes the image to the browser as an HTTP transaction with an HTTP header containing the IMAGE/GIF or IMAGE/JPEG type. Suppose you have a recordset named Rs that contains the image column Prod_pic in the Store database's Product table. This code demonstrates how to apply the ASP Response object's BinaryWrite method, where Cn is an instance of the ADO Connection object:


Response.Buffer = TRUE
Response.Clear
Response.ContentType = "image/gif"
Sql = "SELECT Prod_pic FROM" & _
      "Product WHERE Prod_id = 2"
Set Rs = Cn.Execute(Sql, , _ adCmdText)
Response.BinaryWrite Rs("Prod_pic")
Response.End

You must use the Response object's Clear method; otherwise users will see only ASCII in the browser, not the image. However, the Clear method erases any buffered HTML output. As a result, this piece of code displays only an image on the screen.

There's a better way to display images that allows you to have HTML together with the image. This method circumvents the management problems of image data, because it centralizes image data in the database. Use the Field object's GetChunk method in ADO to retrieve the BLOB's content. Then, save the BLOB's content to a disk file using the VB Put statement. You don't need to worry about what type of images (GIF or JPG) are stored in the database. After you create the image file, you can put its path as the SRC attribute in the IMG tag.

Mark
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
aulrichCommented:
Check out this page:

http://www.asptoday.com/articles/19990524.htm

aulrich
0
 
mgfranzCommented:
Aulrich,  Did you notice that the code snippet from your reference is exactly like my previous post?  Interesting...  I like the fact that everything is pretty much fully explained in detail though.

The key statement is the content type;

Response.ContentType = "image/gif"

THis is the key to posting the reference correctly,

Hope this helps.

Mark
0
 
dgwestAuthor Commented:
I've read that article in the past and I wasn't impressed with it.  I did get it working thanks to NickRackham's post though.  Sorry for asking a question that was previously asked and thanks for the help. Derek.
0
 
mgfranzCommented:
While Nick's solution is an OK one, it might create a headache later if the image directory grows to large proportions...  how will you know if an image should be deleted when an employee leaves the company.  It would be east to write a script that would delete every instance that is associated with a certain employee, including the image file.

Since you have already created a record for the file name, why not store the file itself instead of just the name?

My two cents.

Mark
0
 
NickRackhamCommented:
Derek,

May I post as an answer?

Nick
0
 
dgwestAuthor Commented:
Yep
0
 
NickRackhamCommented:
Many Thanks
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now