Wednesday, January 28, 2009

Re: Multiple Uploads with MeioUpload

No worries. Glad to help.

John

On Jan 28, 3:06 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
> Perfect, this is exactly what I was hoping for. Thank you very much
> for your help with this.
>
> On Jan 28, 8:43 am, Flipflops <johnsv...@googlemail.com> wrote:
>
> > Hi
>
> > Well you can include a seperate field in your model for each upload,
> > something like filename1, filename2 etc. - and thinking about it this
> > does work with saveAll - but I needed felxibility and the advantage of
> > having a seperate model just for uploads is you get to store all the
> > meta data too...
>
> > So only one instance of meio - in the upload model.
>
> > I have:
>
> > class Upload extends AppModel {
>
> >         var $name = 'Upload';
>
> >         /* use the upload compaonent */
> >         var $actsAs = array(
> >                 'Polymorphic',
> >                 'MeioUpload' => array(
> >                         'filename' => array(
> >                                 'dir' => 'img{DS}{model}{DS}{field}',
> >                                 'create_directory' => true,
> >                                 'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/png',
> > 'application/pdf', 'image/gif'),
> >                                 'allowed_ext' => array('.jpg', '.jpeg', '.png', '.pdf', '.gif'),
> >                                 'thumbsizes' => array(
> >                                         'small'  => array('width'=>60, 'height'=>60, 'image_options' =>
> > array('zc' => 1)),
> >                         'medium' => array('width'=>220, 'height'=>220),
> >                         'large'  => array('width'=>800, 'height'=>600)
> >                                 )
> >                                 /*'default' => 'default.jpg',*/
> >                         )
> >                 )
> >         );
>
> > }
>
> > and
>
> > class Product extends AppModel {
>
> >         var $name = 'Product';
>
> >         var $hasMany = array(
> >         'Upload' => array(
> >             'className' => 'Upload',
> >             'foreignKey' => 'foreign_id',
> >             'conditions' => array('Upload.class' => 'Product'),
> >             'dependent' => true
> >         )
> >     );
>
> > }
>
> > John
>
> > On Jan 28, 2:11 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > That should help actually, as I am also using a seperate table to hold
> > > the images and then using associations to link them together. I am
> > > wondering though, how is your model coded to handle this, is it the
> > > same as it is for one image, or do you have to include a seperate
> > > entry of MeioUpload for each file input you have on your view form?
>
> > > On Jan 28, 8:04 am, Flipflops <johnsv...@googlemail.com> wrote:
>
> > > > Hi
>
> > > > I'm using MeioUpload for a current project with multiple images. It is
> > > > a bit more complicated as I'm saving all the images into a single
> > > > table using a ploymorphic association (ie. Product hasMany Upload,
> > > > Profile hasOne Upload etc.) - but this should be helpful anyway
>
> > > > The upload fields generated in the view are organised like so:
>
> > > > <div class="input file">
> > > >         <label for="Upload1Filename">Filename</label>
> > > >         <input type="file" name="data[Upload][1][filename]" value=""
> > > > id="Upload1Filename" />
> > > > </div>
> > > > <div class="input file">
> > > >         <label for="Upload2Filename">Filename</label>
> > > >         <input type="file" name="data[Upload][2][filename]" value=""
> > > > id="Upload2Filename" />
> > > > </div>
>
> > > > etc.
>
> > > > For whatever reasons - probably the polymorphic association - I never
> > > > got this to work with saveAll, but anyway I have a bit of code to
> > > > upload / save the images uploaded from which ever model in
> > > > app_controller like this: (simplified example)
>
> > > > function upload_something($id = null) {
> > > >                 // id is the primary key of the parent model e.g Product
> > > >                 // e.g. Product hasMany Uploads
> > > >                 if (!$id) {
> > > >                         $this->flash(__('Invalid ' . $this->modelClass, true), array
> > > > ('action'=>'admin_index'));
> > > >                 }
>
> > > >                 if(!empty($this->data)){
>
> > > >                         if(isset($this->data['Upload'])){
>
> > > >                                 $upload_errors = array();
>
> > > >                                 foreach($this->data['Upload'] as $Upload => $value){
>
> > > >                                                         // only process the upload if it has actually been uploaded
> > > >                                                         if(!empty($value['filename']['name'])){
>
> > > >                                                                 $this->{$this->modelClass}->Upload->create();
>
> > > >                                                                 $value['class'] = $this->modelClass;
> > > >                                                                 $value['foreign_id'] = $id;
> > > >                                                                 $this->{$this->modelClass}->Upload->save($value);
>
> > > >                                                                 if(!empty($this->{$this->modelClass}->Upload->validationErrors)){
>
> > > >                                                                         $upload_errors[$Upload]['filename'] =  $this->{$this->modelClass}->Upload->validationErrors['filename'];
>
> > > >                                                                 }
> > > >                                                         }
>
> > > >                                 }
> > > >                         }
> > > >                 }
> > > >         }
>
> > > > Hope this helps.
>
> > > > John
>
> > > > On Jan 25, 10:57 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > > > I just recently started using the MeioUpload behaviour that I found
> > > > > and I love it. However I am struggling to figure out how I can be
> > > > > using it to do multiple file uploads.
>
> > > > > I have a table and a seperate model and controller just for uploading
> > > > > images, so one row in said table is equal to one image. Now I just
> > > > > need to figure out how to use MeioUpload to upload multiple images in
> > > > > one go (10 to be exact).
>
> > > > > Any help on this would be greatly appreciated, thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: