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:
Post a Comment