php - How to exclude a form file field on $this->save()? -
when user created upload file.
i want edit user, but, when save , not select file, in other words, wants keep original, error:
sql query: update `societario`.`attorneys` set `nome` = 'teste', `empresa` = 'sotreq', `filial` = 'matriz', `unidade` = 'energia', `alcada` = 'até 50.000', `validade` = '', `arquivo` = array `societario`.`attorneys`.`id` = '42' if user dont select file, want save dont $this->attorney->data['attorney']['arquivo']
my edit.php
function edit($id = null) { $this->attorney->id = $id; $this->set('poderes',$this->attorney->power->find('list', array('fields' => 'resumo'))); if ($this->request->is('get')) { $this->request->data = $this->attorney->read(); } else { if ($this->attorney->save($this->request->data)) { $targetfolder = 'societario/app/webroot/uploads/'; // relative root $tempfile = $this->request->data['attorney']['arquivo']['tmp_name']; $targetpath = $_server['document_root'] . $targetfolder; $targetfile = rtrim($targetpath,'/') . '/' . $this->request->data['attorney']['arquivo']['name'];; move_uploaded_file($tempfile,$targetfile); $this->attorney->updateall( array('arquivo' => "'".$this->request->data['attorney']['arquivo']['name'] ."'"), array('id' => $id)); $this->session->setflash('usuário editado com sucesso!', 'default', array('class' => 'flash_sucess')); $this->redirect(array('action' => 'usuarios')); } } } if try upload file isn't working either. same error.
first, exclude field, unset key in array, before call save:
unset($this->attorney->data['attorney']['arquivo']); second, file uploads, should consider using plugin out - save world of pain! use https://github.com/josegonzalez/upload
Comments
Post a Comment