Managing Image Uploading within Zend Framework

530 views Asked by At

My app uploads an image and stores the image info in the database. If needed it manipulates the image. There are several points in the site where images can be managed like this.

In each case I have an action imageuploadAction() that handles things. Because I have slightly different requirements depending on the part of the site the image is going to be used in there are several different imageuploadActions in various controllers of the site. I want to combine them all into one, however, to make the app easier to manage.

So, my question is what is the best way to handle a site wide image upload capability within Zend Framework? I feel it must either be:

  1. Have one action that does it all and the various controllers would use that action, or...

  2. Create some sort of plugin that does it. An Action Helper Plugin perhaps? Maybe a controller plugin of some sort? What sort of plugin is the best way to do this?

I'm inclined to think 2 is the way to go but want your feedback on this. Thanks!

Oh, and the plugin (or action) will handle physically uploading the photos, categorizing them, flagging them for various uses, resizing as needed, passing data to the DB for all CRUD actions as necessary, etc. etc.

1

There are 1 answers

0
Tim Fountain On BEST ANSWER

What you are describing is what action helpers were designed for, so I'd suggest creating an action helper for handling uploads and moving as much of your processing code into that as possible. However you still need to call that helper from your controllers, so then it really comes down to what suits your application - a central controller that handles the uploads (by calling your helper) or calling the helper from the relevant points in your existing controller methods.

If you can get to a point where your image upload actions are as simple as this:

public function imageuploadAction()
{
    if ($this->_helper->HandleImageUpload([...])) {
        [...]
    }
}

then I'd say you're in pretty good shape, and you can always reuse the helper elsewhere if any parts of your app need to handle an image upload and some other data in the form at the same time.