CakePHP - 管理多个文件上载字段并正确处理它们

时间:2013-03-11 14:44:17

标签: cakephp upload

我一直在困扰并寻找解决方案已经有一段时间了。

我正在计划与CakePHP一起度假的优惠数据库。数据关系在这一点上运行良好。现在我有一个掩码“添加优惠”,可以在不同的字段中上传多个图像,例如有可用的字段:

Name: 
Location:
Image 1:
Image 2:
Image 3:
Image 4: 

我如何为每个提供的字段处理文件上传并将其插入正确的字段到数据库中?我考虑过多个上传字段,但客户不希望这样。是否有可能采用开关盒的解决方案?

非常感谢任何建议。

1 个答案:

答案 0 :(得分:2)

只需创建多个字段,例如客户端询问。

但是将它们作为数组存储在$this->data中但执行以下操作。

echo $this->Form->input('image.' , array('type' => 'file' , 'label' => 'image 1'));
echo $this->Form->input('image.' , array('type' => 'file' , 'label' => 'image 2'));

不要忘记图像后的点

现在当你pr($this->data)时,你会得到类似下面的内容

Model => {
image => { 
[1] =>{image info error etc}
[2] =>{image info error etc}
}}