cakephpでUploadPackを使い、画像を複数アップロードしたいと考えております。
その際に、テーブルは、
create table images(
id int not null auto_increment primary key,
post_id int not null,
img_file_name varchar(255),
img2_file_name varchar(255),
img3_file_name varchar(255),
img4_file_name varchar(255),
created datetime,
modified datetime
)
add.ctpは
lang
1<?php echo $this->Form->create('Image', array('type' => 'file')); ?> 2<?php echo $this->Form->file('img');?> 3 <?php echo $this->Form->error('Image.img');?> 4 <?php echo $this->Form->file('second');?> 5<?php echo $this->Form->error('Image.img2');?> 6<?php echo $this->Form->file('img3');?> 7<?php echo $this->Form->error('Image.img3');?> 8<?php echo $this->Form->file('img4');?> 9<?php echo $this->Form->error('Image.img4');?> 10
で、コントローラaddアクションは
lang
1 2public function add() { 3 if(!empty($this->request->data)) { 4 if($this->Image->saveAll($this->request->data)) { 5 $this->redirect(array('action'=>'index')); 6 } 7 } 8 }
です。
この時、img_file_nameの一枚だけは保存されるのですが、他のimg2,img3,img4は保存されません。ちなみにsaveAllをsaveにしてもダメでした。ちなみに$this->request->dataの中身は```lang-php
array(
'Image' => array(
'post_id' => '35',
'img' => array(
'name' => 'photo03.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/Applications/MAMP/tmp/php/phpziwhsy',
'error' => (int) 0,
'size' => (int) 42497
),
'second' => array(
'name' => 'photo02.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/Applications/MAMP/tmp/php/phpCgwmQ6',
'error' => (int) 0,
'size' => (int) 91961
),
'img3' => array(
'name' => 'photo04.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/Applications/MAMP/tmp/php/phpueV7jE',
'error' => (int) 0,
'size' => (int) 6770
),
'img4' => array(
'name' => 'photo01.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/Applications/MAMP/tmp/php/phpnlEXSz',
'error' => (int) 0,
'size' => (int) 102821
)
)
)
となっております。 力を貸してくれると嬉しいです。よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。