Hi Martin,

I use a slightly different technique than what most people do, with
pretty good results on the few sites I have used it on.

I have a main behaviour which takes care of filesystem<-->database
synchronization and the majority of metadata (filesize, filemtime, md5
of file, etc)

class FileBehavior extends ModelBehavior

and subclasses for each kind of file, which handle special meta data,
like width/height, duration, codec type, etc.

class VideoBehavior extends FileBehavior
class ImageBehavior extends FileBehavior
class DocumentBehavior extends FileBehavior

and then I have an UploadsController which saves all uploads to a
temporary folder and database table. From the ImagesController/
VideosController, etc. I move the records from.

In the ImagesController I have a method that resizes and renders
thumbnails based on url parameters (using phpThumb class), so the
images are generated on demand (and cached obviously). I have a helper
which constructs the image url based on the parameters I pass to it.
This means that I keep the size of the thumbnail separate out of the
model and into the view where it belongs (in my opinion). Plus it
means I can modify the image based on where I am using it, whether
that be flash or html, or a different sized template.

Another reason why I have separated this is so I can use a swf
uploader such as SWFUpload to upload multiple files at once with a
upload progress indicator. I use ajax to retrieve the uploads once
they are complete and display thumbnails/icons on the page without
having to refresh.

I'm still refining the system, but have found it has saved me lots of
time, especially if the frontend interface has changed and I need to
render a different image size. Also, because it handles directory
syncronization with the database, I can upload all my images/videos/
documents/etc by FTP, and not having to upload each one manually in my
admin section.

Hope this helps you realise there are many ways to do this, and
everything doesn't have to be tied together like many of the solutions
posted by others. One day I hope to release the code, but can't right
now.

Cheers,
Adam


On Nov 28, 6:32 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Nov 27, 6:40 pm, mbavio <[EMAIL PROTECTED]> wrote:
>
> > Hi, I´m trying to solve an upload problem. I want to upload images,
> > and in the same processe some thumbnails of different sizes have to be
> > done too. I´ve checked some behaviours that seems to do that (AD7six
> > behaviour, ActAs Image behaviour, digitalspaghetti behaviour) and some
> > components (Image Upload Component) but I cant figure out if these
> > behaviours create the images in the file system or directly in the
> > database. Can anyone help me?
>
> > Thanks. Martin
>
> I know that ditital's and my behaviors store the files on the file
> system and meta data in the db.
>
> For the generic upload behavior (for which there is a sample
> application on cakeforge in the noswad project) if you want to
> generate the thumbs on save, you don't configure that; you'd add
> something like this to your model afterSave function:
>
> function afterSave($created) {
>      if ($created) {
>           $path = IMAGES . 'thumbs' . 'pic.jpg';
>           $path2 = IMAGES . 'thumbs' . 'pic_ito.jpg';
>           $this->resize(null, $width, $height, $path);
>           $this->resize(null, $width/2, $height/2, $path2);
>      }
>
> }
>
> OR you could add the calls in your image upload behavior in the
> _afterProcessUpload method if you wanted.
>
> hth,
>
> AD
> PS. Note that the sample application shows an example of use, it
> doesn't show the only way you can/should use the generic upload
> behavior.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to