Question

I really need help on this one. i want to allow user to multiple upload with single brows.

view is like this:

<?php echo $this->Form->create('TypologyPicture', array('type'=>'file')); ?>
        <legend><?php echo __('Add Picture'); ?></legend>
    <?php
        echo $this->Form->input('id');
        echo $this->Form->input('typology_id');
        echo $this->Form->input('pic_path', array('label'=>'Picture','type'=>'file','multiple'=>'multiple'));

    ?>
<?php echo $this->Form->end(__('Submit')); ?>
</div>

and the controller is like this:

/**
 * add method
 *
 * @return void
 */
    public function add() {
        if ($this->request->is('post')) {
            $this->TypologyPicture->create();
            if ($this->TypologyPicture->save($this->request->data)) {
                $this->Session->setFlash(__('The typology picture has been saved.'));
                return $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The typology picture could not be saved. Please, try again.'));
            }
        }
        if ( AuthComponent::user('role')==='admin' ||AuthComponent::user('role')==='superadmin' ){
            $typologies = $this->TypologyPicture->ItemTypologyPicture->find('list');
        } else {
            $typologies = $this->TypologyPicture->ItemTypologyPicture->find('list', array('conditions' => array('ItemTypologyPicture.user_id' => AuthComponent::user('id'))));
            }
        $this->set(compact('typologies'));
    }

So what i want to achieve is that when the user click browse, he can select multiple images, and also selects a typology where this pic belonges to. so when he clicks submit all the phottos selected uploads and belonges to the typology he just selected. so how can i save all the images paths in db with just one submit??

Thanx

Was it helpful?

Solution

This is pretty clearly explained in the section of the CakePHP Book on Saving Your Data, particularly the part on saveAll()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top