How to upload multiple files at same time in CakePHP 2 -
i have function upload images in cakephp 2. works fine, upload 1 file @ same time. how upload multiple images @ same time. sorry english!
controller
public function add() { $this->set('title_for_layout', 'file'); $this->loadmodel('file'); if(!empty($this->data)){ $data = $this->data; $file = $data['file']['filename']; if($file['name'] != null){ $data = $this->data; $file = $data['file']['filename']; move_uploaded_file($file['tmp_name'], www_root . 'uploads/' . $file['name']); $data['file']['title'] = $this->data['file']['title']; $data['file']['description'] = $this->data['file']['description']; $data['file']['filename'] = $file['name']; $this->file->save($data,false); $this->session->setflash(__('added.', true)); $this->redirect(array('action'=>'file')); }else{ $this->session->setflash(__('wrong', true)); $this->redirect(array('action'=>'file')); } } }
view
<?php echo $this->form->input('filename', array('type' => 'file')); ?>
thanks.
sorry delayed answer.
the basic structure following:
view:
<?php echo $this->form->create('model', array('type'=>'file')); ?> <?php echo $this->form->input('image.0', array('type' => 'file')); ?> <?php echo $this->form->input('image.1', array('type' => 'file')); ?> <?php echo $this->form->input('image.2', array('type' => 'file')); ?> <?php echo $this->form->input('image.3', array('type' => 'file')); ?> <?php echo $this->form->end('save all');
controller:
function index() { if($this->request->is('post', 'put')) { $this->model->saveall($this->request->data['image']); } }
model:
function beforesave() { foreach($this->data $k, $v) { //code here } }
Comments
Post a Comment