php - How to upload bulk records in CAKEPHP -
a 4 column dashboard 10 rows
provided wherein user can enter
details follows:
column 1 – file category column 2 – file type column 3 - file reference column 4 – upload file (any type)
upload button– uploads details of documents entered simultaneously
i unable upload records in database last recording saving in database kindly me
usercontrolle.php (my controller)
<?php app::uses('appcontroller', 'controller'); class filescontroller extends appcontroller { public $helpers=array('html','form'); public $components = array('requesthandler'); /*function display files details*/ public function index() { $this->set('files', $this->file->find('all')); } /*function add file record database */ public function add() { if ($this->request->is('post')) { $this->file->create(); if(empty($this->data['file']['url']['name'])) { unset($this->request->data['url']['file']); } if(!empty($this->data['file']['url']['name'])) { $file=$this->data['file']['url']; $file['name']=$this->sanitize($file['name']); $this->request->data['file']['url'] = time().$file['name']; if($this->file->save($this->request->data)) { move_uploaded_file($file['tmp_name'], app . 'outsidefiles' .ds. time().$file['name']); return $this->redirect(array('action' => 'index')); $this->session->setflash(__('your file has been saved.')); //return $this->redirect(array('action' => 'index')); } } $this->session->setflash(__('unable add file.')); } } }
add.ctp (my view)
<h1>add file</h1> <?php echo $this->form->create('file',array('enctype'=>'multipart/form-data')); echo $this->form->input('category', array( 'options' => array( 'passport' => 'passport', 'pancard' => 'pancard', 'driving license' => 'driving license', 'others' => 'others') )); echo $this->form->input('type', array( 'options' => array( 'image' => 'image', 'office' => 'office', 'technical' => 'technical', 'others' => 'others') )); echo $this->form->input('reference'); echo $this->form->input('url', array('type' => 'file')); echo $this->form->input('category', array( 'options' => array( 'passport' => 'passport', 'pancard' => 'pancard', 'driving license' => 'driving license', 'others' => 'others') )); echo $this->form->input('type', array( 'options' => array( 'image' => 'image', 'office' => 'office', 'technical' => 'technical', 'others' => 'others') )); echo $this->form->input('reference'); echo $this->form->input('url', array('type' => 'file')); echo $this->form->input('category', array( 'options' => array( 'passport' => 'passport', 'pancard' => 'pancard', 'driving license' => 'driving license', 'others' => 'others') )); echo $this->form->input('type', array( 'options' => array( 'image' => 'image', 'office' => 'office', 'technical' => 'technical', 'others' => 'others') )); echo $this->form->input('reference'); echo $this->form->input('url', array('type' => 'file')); echo $this->form->end('save file');
how bulk save anything? looks saving uploaded file db. not idea name model file
conflicts core class can cause bunch of problems.
generally if want bulk insert, want read rows out of csv, loop on them , call create()
, save()
on each one.
Comments
Post a Comment