Hello,

I try to send this again cause it looks like the first email never was received.

I have created a plugin[1] that allows at least for me for a bit
easier file uploading, manipulation and control of uploaded files that
is attached to a database. It is  heavily inspired from the
UploadColumn[2] and the PaperClip[3] plugins that is available for
Ruby on Rails.

This is a plugin to Zend_Db_Table that is using the really great
Zend_Db_Table_Plugin[4] proposal.

Pull it from gitorious http://gitorious.org/projects/gem or download
it from here 
http://gitorious.org/projects/gem/repos/mainline/archive/master.tar.gz

## A short demonstration

Suppose we have a table named photos. That table has an column named
image where we store the filename of an uploaded image. To display
different versions  of that image all you have to do in your view is
the following.

echo $photo->image->small->url();
echo $photo->image->medium->url();

You are fetching the row object as usal using.

$photos = new Photos();
$this->view->photo = $photos->fetchRow($photos->select()->where('id =
?', <your photo id here>));

Saving the image is just as easy as displaying it. (You could use
Zend_Form and Zend_File.. instead)

$photos = new Photos();
$photo = $this->createRow();
$photo->image = new ArrayObject($_FILES['userfile']); // Or a real
path to an existing file
$photo->save();

For the above to work you need to have a model named Photos and little
bit of configuration to it. I hope that the example below can explain
it self.

class Photos extends Zend_Db_Table
{
   protected $_attachment = array(
       'column'      => 'image',
       'store_path'  => /my/store/path/,
       'manipulator' => 'ImageTransform',
       'styles' => array(
           'small' => array(
                'geometry' => '200x200'),
           'medium' => array(
                'geometry' => '500x500'),
       ),
   );

   protected function _setupPlugins()
   {
       $attachment = new Gem_Db_Table_Plugin_Attachment($this->_attachment);
       $this->addPlugin($attachment);
   }
}

In the example above images are stored in the following directory,
"/my/store/path/photos/<id of the uploaded photo>", but that is
configurable.

Ok, hope you like it. If you decide to test it please be gentle and I
will try my best to help you through the setup if there are any
problems, please email me any bugs you find or feel free to clone it
at gitorious and improve it.

I created this plugin for my personal photo gallery[5] so if you like
you can see how it is used there.

[1]: http://gitorious.org/projects/gem
[2]: http://www.thoughtbot.com/projects/paperclip
[3]: http://uploadcolumn.rubyforge.org/
[4]: 
http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_Table_Plugin+-+Simon+Mundy%2C+Jack+Sleight
[5]: http://gitorious.org/projects/yag

Reply via email to