Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何排除$this上的表单文件字段->;save()?_Php_Cakephp - Fatal编程技术网

Php 如何排除$this上的表单文件字段->;save()?

Php 如何排除$this上的表单文件字段->;save()?,php,cakephp,Php,Cakephp,当用户被创建时,他上传一个文件 我想编辑此用户,但是,当他保存且未选择任何文件时,换句话说,他希望保留原始文件,我得到以下错误: SQL Query: UPDATE `societario`.`attorneys` SET `nome` = 'teste', `empresa` = 'Sotreq', `filial` = 'Matriz', `unidade` = 'Energia', `alcada` = 'Até 50.000', `validade` = '', `arquivo` =

当用户被创建时,他上传一个文件

我想编辑此用户,但是,当他保存且未选择任何文件时,换句话说,他希望保留原始文件,我得到以下错误:

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->departney->data['departney']['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 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'));
    }
}

}
如果我尝试上载文件也不起作用。同样的错误。

看看:

`arquivo` = Array

原始MySQL查询不会处理数组。您需要将数组处理为MySQL将理解的数据类型。

首先,要排除该字段,请先在调用save之前,先在数组中取消该键:

unset($this->Attorney->data['Attorney']['arquivo']);

第二,对于文件上传,你应该考虑使用插件来帮助你——这将为你节省一个痛苦的世界!我用

是的,我知道。。。如果没有选择任何文件,我想排除该字段。啊,好的@乔舒亚。佩林得到了你需要的。当没有文件上传时,您只需要将其放入一个条件中<代码>如果(!isset($this->request->data['authority']['arquivo']['tmp_name']){…