cakephp错误插件上传程序Miles J
我在cakephp 2中有一个站点,我想用Miles J的插件上传器上传一个文件。 但请将此错误返回给我: 未找到列:“字段列表”中的1054未知列“数组” SQL查询:cakephp错误插件上传程序Miles J,cakephp,plugins,file-upload,cakephp-model,Cakephp,Plugins,File Upload,Cakephp Model,我在cakephp 2中有一个站点,我想用Miles J的插件上传器上传一个文件。 但请将此错误返回给我: 未找到列:“字段列表”中的1054未知列“数组” SQL查询: UPDATE `db148147_trimalcione`.`ingredient_images` SET `id` = 6, `filename` = Array, `ingredient_id` = 8, `modified` = '2012-08-21 23:01:13' WH
UPDATE `db148147_trimalcione`.`ingredient_images`
SET
`id` = 6,
`filename` = Array,
`ingredient_id` = 8,
`modified` = '2012-08-21 23:01:13'
WHERE `db148147_trimalcione`.`ingredient_images`.`id` = '6'
为什么??
我已经创建了一个包含列文件名的表。
这是我的模型:
<?php
class IngredientImage extends AppModel {
public $name = 'IngredientImage';
public $useTable = 'ingredient_images';
public $actsAs = array (
'Uploader.Attachment' => array (
'filename' => array(
'name' => 'setNameAsImgId', // Name of the function to use to format filenames
'saveAsFilename' => true,
// 'baseDir' => '', // See UploaderComponent::$baseDir
'uploadDir' => '/files/ingredient_images/', // See UploaderComponent::$uploadDir
'dbColumn' => 'filename', // The database column name to save the path to
'defaultPath' => 'default.png', // Default file path if no upload present
'maxNameLength' => 20, // Max file name length
'overwrite' => true, // Overwrite file with same name if it exists - Se si effettua un transform è da usare al suo interno altrimenti c'è un override a false
'stopSave' => true, // Stop the model save() if upload fails
'allowEmpty' => true, // Allow an empty file upload to continue
'transforms' => array (
array('method' => 'resize', 'width' => 160, 'height' => 160, 'dbColumn' => 'filename', 'append' => false, 'overwrite' => true)
)
)
),
'Uploader.FileValidation' => array (
'filename' => array (
'maxWidth' => array (
'value' => 1280,
'error' => 'La lunghezza dell\'avatar non deve superare i 1280 pixel'
),
'maxHeight' => array (
'value' => 1280,
'error' => 'L\'altezza dell\'avatar non deve superare i 1280 pixel'
),
'extension' => array (
'value' => array('gif', 'jpg', 'png', 'jpeg'),
'error' => 'Il formato dell\'avatar deve essere una GIF, JPG o PNG'
),
'filesize' => array (
'value' => 5242880,
'error' => 'La dimensione dell\'avatar non deve superare i 500kB'
)
)
)
);
public $belongsTo = array(
'Ingredient' => array(
'className' => 'Ingredient',
'foreignKey' => 'ingredient_id',
'conditions' => '',
'order' => ''
)
);
public function setNameAsImgId ($name, $field, $file) {
/**
* Format the filename a specific way before uploading and attaching.
*
* @access public
* @param string $name - The current filename without extension
* @param string $field - The form field name
* @param array $file - The $_FILES data
* @return string
*/
// devo ricavare l'id dell'immagine appena creata per rinominare il file
return $this->id;
}
}
?>
我的看法是:
echo $this->Form->create('Ingredient', array ('class' => 'form', 'type' => 'file'));
echo $this->Form->input('IngredientImage.id', array ('type'=>'hidden', 'value'=> $ingredient[0]['IngredientImage']['id'],'label'=> false, 'id' => 'IngredientImage.id'));
echo $this->Form->input('IngredientImage.filename', array('type' => 'file'));
echo $this->Form->submit('Modifica', array('id'=>'edit'));
echo $this->Form->end();
请帮助我检查它使用
pr($this->request->data)打印的内容
您将找到文件名
索引的数组。假设您在$this->request->data['IngredientImage'][filename']['actual\u filename']
获取文件名。然后,您可以使用以下方法对其进行操作:
CakePlugin::load('Uploader');
App::import('Vendor', 'Uploader.Uploader');
//.. my action
$this->request->data['IngredientImage']['ingredient_id'] = $this->Ingredient->id;
$this->request->data['IngredientImage']['filename'] = $this->request->data['IngredientImage']['filename']['actual_filename'];
$this->Ingredient->IngredientImage->save($this->request->data)
//..
用
pr($this->request->data)检查它打印的内容
您将找到文件名
索引的数组。假设您在$this->request->data['IngredientImage'][filename']['actual\u filename']
获取文件名。然后,您可以使用以下方法对其进行操作:
CakePlugin::load('Uploader');
App::import('Vendor', 'Uploader.Uploader');
//.. my action
$this->request->data['IngredientImage']['ingredient_id'] = $this->Ingredient->id;
$this->request->data['IngredientImage']['filename'] = $this->request->data['IngredientImage']['filename']['actual_filename'];
$this->Ingredient->IngredientImage->save($this->request->data)
//..
检查文件夹“uploadDir”=>“/files/component_images/”的权限 这就是我设置的问题
希望它能帮助您检查“uploadDir”=>“/files/component_images/”文件夹的权限 这就是我设置的问题
希望它能帮助我好吧,我尝试过这种方法,并将我的记录更新到数据库中,但没有上传我的文件。我不知道为什么我尝试了这种方法,并将我的记录更新到数据库中,但没有上传我的文件。我不知道为什么