我正在开发一个应用程序,其中我创建了一个products
具有以下属性的表。
{id, image, warranty-image, created, modified}
我miles johnson 4.3.1 uploader
用来上传图片。所以我写$actsAs
了Product model
如下。
public $actsAs = array(
'Uploader.Attachment' => array(
'image' => array(
'overwrite' => true,
'uploadDir' => 'img/products',
'finalPath' => '',
'dbColumn' => 'image',
'transforms' => array(
'imageLarge' => array(
'nameCallback' => 'transformNameCallback',
'method' => 'resize',
'prepend' => 'large_',
'width' => 750,
'height' => 100,
'aspect' => false
)
),
'warranty_image' => array(
'overwrite' => true,
'uploadDir' => 'img/products',
'finalPath' => '',
'dbColumn' => 'warranty_image',
'transforms' => array(
'warranty_imageSmall' => array(
'nameCallback' => 'transformNameCallback',
'method' => 'resize',
'prepend' => 'small_',
'width' => 150,
'height' => 96,
'aspect' => false
)
)
)
),
'Uploader.FileValidation' => array(
'image' => array(
'required' => true,
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'type' => array('image'),
'minWidth' => 100,
'minHeight' => 100,
'filesize' => 5242880
),
'warranty_image' => array(
'required' => true,
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'type' => 'image',
'minWidth' => 100,
'minHeight' => 96,
'filesize' => 5242880
)
)
);
public function transformNameCallback($name, $file) {
return $this->getUploadedFile()->name();
}
在add view
我写file inputs
如下。
echo $this->Form->create('Product', array('enctype' => 'multipart/form-data'));
echo $this->Form->file('image');
echo $this->Form->file('warranty_image');
echo $this->Form->end();
这个上传者只上传image
图片而不上传warranty_image
图片。请帮助我获得解决方案。这项工作将受到更多赞赏。