On 27 Jan, Karsten Kraus wrote:
> I'm currently comparing Zope against Midgard,
> in Zope there is the possibility for uploading
> images to, I think the ZODB (Zope Object Database),
> not just entering it's physical path, but the complete
> (binary) image data...
<snip>
> Will it be difficult, to just add an "imgdata" field to the midgard-database,
> and write some routine in php which lets me upload the image, store it in the db
> and access it via something like a special topic-tree?
> Could even I (midgard & php newbie) do that with some time?

At this point Midgard doesn't directly support
serving images from the database. 

However, it is possible to use the article attachment
functionality for this. The Admin site doesn't have an
UI for this, though, so you will have to write one 
yourself.

Also, Emile is working on "blob" file serving for 
Midgard 2, which should make handling all file
formats much easier.


Here are some code snippets that could help you
started. I'm just copying these over from Midgard's
site so they probably need some modification to
work on your site.

First, create an active page (for example, /images) 
for your site, and place the following to the 
code-init for that page:

<?php
$TOPIC = 123;
if ($argc == 2 && is_article_in_topic_tree($TOPIC, $argv[0])
    && ($article = get_article($argv[0]))
    && ($files = list_files($article->id))) {
  while ($files->fetch())
    if ($files->name == $argv[1] && ($file = get_file($files->id))) {
       header('Content-type: ' . $file->type);
       header('Content-length: ' . $file->size);
       readfile($file->content);
       exit();
    }
}
?>

And for the administration interface, here is a
function that could be useful:

<?php
  function add_attachment($article, $name, $file) {
    $fname = tempnam('/opt/midgard', 'att');
    copy($file, $fname);
    if (substr($name, -3) == '.gz')
      $type = 'application/x-gzip';
    elseif (substr($name, -4) == '.rpm')
      $type = 'application/x-rpm';
    elseif (substr($name, -4) == '.jpg')
      $type = 'image/jpeg';
    elseif (substr($name, -4) == '.gif')
      $type = 'image/gif';
    elseif (substr($name, -4) == '.png')
      $type = 'image/png';
    else
      $type = 'application/octet-stream';
    $md5 = explode(' ', exec("md5sum $fname"));
    create_file($article, $type, $name, $fname, filesize($fname), $md5[0]);
  }
?>

Hopefully these help you to get started...

> Karsten

/Bergie

-- 
-- Henri Bergius -- +358 40 525 1334 -- [EMAIL PROTECTED] --
               http://www.iki.fi/Henri.Bergius


--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org

To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]

Reply via email to