【问题标题】:CakePHP file upload errorsCakePHP 文件上传错误
【发布时间】:2014-01-26 05:01:40
【问题描述】:

我的数据库遇到了这个错误,说我的数组有问题:

数据库错误

错误:SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列'数组'

SQL 查询:UPDATE `mongexc_cake214`.`configurations` SET `id` = 1, `username` = 'bill clinton', `profession` = 'president', `description` = 'Ob Jones-D is a Thai按摩和电子针灸专家。 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 '

注意:如果要自定义此错误信息,请创建 app/View/Errors/pdo_error.ctp

这是我的 edit.php 文件的一部分,其中包含用于上传图片文件的字段 userphoto

<?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')); ?>

【问题讨论】:

  • 你是如何在你的相关控制器中处理传入的userphoto文件数组信息的?
  • 谢谢!这是我的要点link。我在'edit.ctp'

标签: php cakephp file-upload cakephp-2.0


【解决方案1】:

userphoto 是一个文件字段,它将包含类似如下的数据:

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

这意味着它是一个数组。

但是在您的代码中,您直接将一个数组插入到您的数据库中。您需要明确处理文件上传。

查看Best practice to upload files in CakePHP

【讨论】:

  • 谢谢徐鼎!也感谢链接
【解决方案2】:
$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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2011-04-24
    相关资源
    最近更新 更多