2014-01-08 27 views
0

我遇到這個錯誤與我的數據庫說,我有一個數組的一些問題:CakePHP的文件上傳錯誤

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

SQL Query: UPDATE `mongexc_cake214`.`configurations` SET `id` = 1, `username` = 'bill clinton', `profession` = 'president', `description` = 'Ob Jones-D is a Thai Massage and Electronic Acupuncture Specialist. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, repellat optio officiis neque ea repudiandae sint corrupti illo? Maiores adipisci mollitia quae perferendis numquam minima deserunt ratione placeat rem. Numquam?', `tel_mobile` = '000-000-0000', `address` = '000 new york of africa V99 999', `userphoto` = Array WHERE `mongexc_cake214`.`configurations`.`id` = '1'

Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp

這是與現場userphoto我edit.php文件的一部分用於圖像文件上傳

<?php echo $this->Form->create('Configuration', array('type' => 'file')); ?> 
<fieldset> 
<legend><?php echo __('Edit Configuration'); ?></legend> 
<?php 
echo $this->Form->input('id'); 
echo $this->Form->input('username'); 
echo $this->Form->input('profession'); 
echo $this->Form->input('description', array('type' => 'textarea','label' => 'Content of this Article', 'rows' => '10', 'cols' => '120')); 
echo $this->Form->input('userphoto', array('type' => 'file')); 
echo $this->Form->input('tel_mobile'); 
echo $this->Form->input('address'); 
?> 
</fieldset> 
<?php echo $this->Form->end(__('Submit')); ?> 
+0

你是如何處理你的相關_controller_傳入'userphoto'文件陣列信息? – summea

+0

Thks summea!這是我的要點[鏈接](https://gist.github.com/guinslym/8313365)。我在'edit.ctp' –

回答

0

userphoto是一個文件字段,它將包含作爲類似的數據:

$this->request->data['Configuration']['userphoto'] = array(
    'error' => …, 
    'name' => …, 
    … 
) 

這意味着它是一個數組。

但是在您的代碼中,您直接將數組插入數據庫。您需要明確處理文件上載。

退房Best practice to upload files in CakePHP

+0

這個徐丁!也爲鏈接 –

0
$imageData = exif_imagetype($this->request->data['Foo']['image']['tmp_name']); 
       image_type_to_mime_type($imageData); 
        switch ($imageData) : 
        case '2': 
         $type = '.jpg'; 
         break; 
        case '3': 
         $type = '.png'; 
         break; 
        default: 
         $type = 'invalid'; 
         break; 
        endswitch; 
$uniq = mt_rand(); 
move_uploaded_file($this->request->data['Foo']['image']['tmp_name'],'path/to/dir'); 
$this->request->data['Foo']['image'] = '/path/to/dir/'.$uniq.$type;