[Zope] Images from database into html

Sven Syld Sven.Syld@stat.ee
Thu, 23 Aug 2001 17:01:34 +0300


> > I have gained access to a employees' database which among=20
> > other stuff contains employees' photos (that is, in binary form).=20
> > I'm trying to  display employees with their names and photos etc.=20
> > HTML page looks like this:
> > <dtml-in sql_employees>
> >   <dtml-var first_name> <dtml-var last_name>=20
> >   <img src=3D"his_or_her_photo"> (which is DTML method)
> But it is not called!

Actually it is called. Even if object is fetched this way. I think problem =
was that when it was called it was not under namespace of <dtml-in =
sql_employees>. But I got it working now (see at the end of this mail).

> What about:
> <dtml-var photo>
Thats no good since it just prints the binary contents in the HTML page. =
My photos are as files, not as a filenames, in database. (I looked around =
a little and read that this is not good practice, but it would be very =
hard for me to do something about it).


Ok, here is what I did.
Database has these fields: person_id, first_name, last_name, photo.
<dtml-in sql_employees>
  <dtml-var first_name> <dtml-var last_name>
  <img src=3D"persons_photo?person_id=3D<dtml-var person_id>">
</dtml-in>

persons_photo is DTML method:
<dtml-in sql_photo><dtml-var photo></dtml-in>
(no linefeeds or spaces between since it would mess up the file and would =
be interpreted incorrectly)

sql_photo is SQL method, which takes attribute: person_id.
SELECT photo FROM employees WHERE person_id=3D<dtml-var person_id>


Sven Syld