首页 文章

CakePHP文件上传错误

提问于
浏览
0

我正在使用我的数据库遇到这个错误,说我有一个数组问题:

数据库错误错误:SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'数组'SQL查询:更新mongexc_cake214 .configurationsSETid= 1,username='bill clinton ',profession='president',description='Ob Jones-D是泰式按摩和电子针灸专家 . Lorem ipsum dolor坐在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',地址'='000非洲纽约V99 999',userphoto =数组WHEREmongexc_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')); ?>

2 回答

  • 0

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

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

    这意味着它是一个数组 .

    但是在您的代码中,您直接将数组插入数据库 . 您需要显式处理文件上载 .

    退房Best practice to upload files in CakePHP

  • 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;
    

相关问题