为什么这个上传文件代码在CakePHP中不起作用

为什么这个上传文件代码在CakePHP中不起作用,php,mysql,cakephp,Php,Mysql,Cakephp,我在CakePHP2.1中上传文件时遇到问题。事实上,我总是有这样的错误: Column not found: 1054 Unknown column 'Array' in 'field list'. 对于视图: <?php echo $this->Form->create('Ecole',array('enctype' => 'multipart/form-data')); ?> <?php echo $this->Form->input('E

我在CakePHP2.1中上传文件时遇到问题。事实上,我总是有这样的错误:

Column not found: 1054 Unknown column 'Array' in 'field list'.
对于视图:

<?php echo $this->Form->create('Ecole',array('enctype' => 'multipart/form-data')); ?>
<?php echo $this->Form->input('Ecole.logo_ecole', array('type'=>'file','class'=>'','label'=>'')); ?>

有人能解释一下我做错了什么以及如何纠正吗?

要处理多部分/表单数据,必须使用帮助器以这种方式指定它

 <?php echo $this->Form->create('Ecole', array('type' => 'file')); ?>


类型可以是“发布”、“获取”、“文件”、“放置”或“删除”。请参见文档中此处的创建选项部分

这可能是因为您试图保存上载文件时生成的数组蛋糕(
$this->data['Ecole']['logo\u Ecole']
是一个数组)。您想只将文件名保存到数据库吗?

我已经修改了您的代码,请查看

请不要删除
数组('enctype'=>“多部分/表单数据”)
表单中的这一行

<?php

if(!empty($this->data))
{    
    debug($this->data);
    $ext  = 'jpg';


      // Destination folder, new filename and destination path
    $dest_folder = IMAGES . DS . 'galleries' . DS . $this->Ecole->id;
    $new_filename = $this->Ecole->id. '.' .$ext;
    $dest_path = $dest_folder . DS . $new_filename;

    // Check if destination folder exists and create if it doesn't
    if(!is_dir($dest_folder))
    {
      mkdir($dest_folder, 0755, true);
    }

    $image='';

    // We move the picture and rename it with his id
    if(move_uploaded_file($this->data['Ecole']['logo_ecole']['tmp_name'], $dest_path))
    {
        $image = basename($this->data['Ecole']['logo_ecole']['name'])

        // Show success flash message
        $this->Session->setFlash(__('Picture successfully added !', true), 'default', array('class' => 'success'));
        echo  "<script>  parent.location.reload(true); parent.jQuery.fancybox.close(); </script>";

    }else
    {
      // Delete picture
      //$this->Ecole->delete($this->Ecole->id);

      // Show error flash message
      $this->Session->setFlash(__('Error occurred while adding picture !', true), 'default', array('class' => 'error'));
    }   


    $this->data['Ecole']['logo_ecole'] = $image;

      // Save success
      if(!$this->Ecole->save($this->data))
      {      
        // Show error flash message
        $this->Session->setFlash(__('Error occurred while adding picture !', true), 'default', array('class' => 'error'));
      }

}

感谢您的回答,但即使我按数组('type'=>'file')更改数组('enctype'=>'multipart/form data'),我仍然有同样的问题?????这是因为您的一行接收的是数组而不是列名。我不太感谢你。当使用你的修改上传工作,但不是插入现在的问题是$this->Ecole->save($this->data)注意:它不会给我任何错误我可以看到你的数据库表请或让我知道你的图像字段名称在数据库tableid int(11)Nom_Ecole varchar(255)address_Ecole text Tel_fix varchar(255)电话号码移动电话号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码号码dt_sup datetime dt_modif datetime这是我的bd表,图像字段名是logo\u ecolete告诉我一件事,你可以只存储图像或使用完整路径,如abc.jpg或uploads/abc.jpguse$image=$this->data['Ecole']['logo\u Ecole']['name'];或$image=“YOUR\u path/”$this->data['Ecole']['logo\u Ecole']['name'];插入$image=basename($this->data['Ecole']['logo\u Ecole']['name'])
<?php

if(!empty($this->data))
{    
    debug($this->data);
    $ext  = 'jpg';


      // Destination folder, new filename and destination path
    $dest_folder = IMAGES . DS . 'galleries' . DS . $this->Ecole->id;
    $new_filename = $this->Ecole->id. '.' .$ext;
    $dest_path = $dest_folder . DS . $new_filename;

    // Check if destination folder exists and create if it doesn't
    if(!is_dir($dest_folder))
    {
      mkdir($dest_folder, 0755, true);
    }

    $image='';

    // We move the picture and rename it with his id
    if(move_uploaded_file($this->data['Ecole']['logo_ecole']['tmp_name'], $dest_path))
    {
        $image = basename($this->data['Ecole']['logo_ecole']['name'])

        // Show success flash message
        $this->Session->setFlash(__('Picture successfully added !', true), 'default', array('class' => 'success'));
        echo  "<script>  parent.location.reload(true); parent.jQuery.fancybox.close(); </script>";

    }else
    {
      // Delete picture
      //$this->Ecole->delete($this->Ecole->id);

      // Show error flash message
      $this->Session->setFlash(__('Error occurred while adding picture !', true), 'default', array('class' => 'error'));
    }   


    $this->data['Ecole']['logo_ecole'] = $image;

      // Save success
      if(!$this->Ecole->save($this->data))
      {      
        // Show error flash message
        $this->Session->setFlash(__('Error occurred while adding picture !', true), 'default', array('class' => 'error'));
      }

}