我在 CakePHP 2.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'=>'')); ?>
当我删除时,array('enctype' => 'multipart/form-data')
我没有错误,但上传也不起作用。
对于控制器:
if(!empty($this->data))
{
debug($this->data);
$ext = 'jpg';
// Save success
if($this->Ecole->save($this->data))
{
// 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);
}
// We move the picture and rename it with his id
if(move_uploaded_file($this->data['Ecole']['logo_ecole']['tmp_name'], $dest_path))
{
// 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>";
}
// Move failed
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'));
}
}
// Save failed
else
{
// Show error flash message
$this->Session->setFlash(__('Error occurred while adding picture !', true), 'default', array('class' => 'error'));
}
}
谁能解释我做错了什么以及如何做对?