【发布时间】:2013-10-28 12:24:33
【问题描述】:
我正在开发一个应用程序,其中我创建了一个具有以下属性的products 表。
{id, image, warranty-image, created, modified}
我正在使用miles johnson 4.3.1 uploader 上传图片。所以我在Product model中写了$actsAs如下。
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 的图片。请帮助我获得解决方案。这项工作将受到更多赞赏。
【问题讨论】:
-
那么真的是上传只为
image选择的文件,还是你的意思是它只是存储只为image选择的文件image,即实际上上传两个文件(浏览器发送两个文件的数据),但为warrant_image选择的文件没有存储在数据库和/或文件系统中? -
@ndm 它只是上传'image'文件并复制到'table',但它没有发生在'warranty_image'中。
-
如果真的是这样,那么生成的 HTML 表单代码和发送的请求(检查控制器中的
debug($this->request->data))究竟是什么样的?
标签: cakephp plugins cakephp-2.3 uploader