创建用户时,他上传文件。
我想编辑这个用户,但是当他保存而不选择任何文件时,换句话说,他想保留原来的,我得到这个错误:
SQL Query: UPDATE `societario`.`attorneys` SET `nome` = 'teste', `empresa` = 'Sotreq', `filial` = 'Matriz', `unidade` = 'Energia', `alcada` = 'Até 50.000', `validade` = '', `arquivo` = Array WHERE `societario`.`attorneys`.`id` = '42'
如果用户不选择任何文件,我希望保存不要得到$this->Attorney->data['Attorney']['arquivo']
我的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 to the 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'));
}
}
}
如果我尝试上传文件也不起作用。同样的错误。