CakePHP文件上传错误 [英] CakePHP file upload errors
问题描述
我遇到这个错误,我的数据库说我有一个数组的问题:
I'm running into this error with my database saying that I have some issue with an array:
数据库错误
Database Error
错误:SQLSTATE [42S22]:未找到列:1054字段列表中的未知列Array
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'
SQL查询:UPDATE`mongexc_cake214`.`configurations` SET` id` = 1,`username` ='bill clinton',`profession`='president',`description` ='Ob Jones-D是一个泰式按摩和电子针灸专家。 Lorem ipsum dolor sit amet,consectetur adipisicing elit。 Quam,repellat optio officiis neque ea repudiandae sint corrupti illo? Maîresadipisci 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 '
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'
注意:如果您要自定义此错误消息,请创建app / View / Errors / pdo_error.ctp
Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp
这是我的 edit.php 文件的一部分,其中包含用于图片文件上传的字段 userphoto
This is part of my edit.php file with the field userphoto for image file upload
<?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')); ?>
推荐答案
$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;
这篇关于CakePHP文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!