我想用codeigniter中的描述上傳多個圖像。一切都很好,圖像上傳,圖像文件名發送到數據庫,但「描述」不會去數據庫,我錯在哪裏?用codeigniter在mysql中插入多行
form code is like this
File 1: <input type="file" name="image1" /><br />
Descr: <input type="text" name="description[]" size="50" value="" /><br/><br/>
File 2: <input type="file" name="image2" /><br />
Descr: <input type="text" name="description[]" size="50" value="" /><br/><br/>
File 3:<input type="file" name="image3" /><br />
Descr: <input type="text" name="description[]" size="50" value="" /><br/><br/>
和模式是這個
for($i = 1; $i < 6; $i++) {
/* Handle the file upload */
$upload = $this->upload->do_upload('image'.$i);
/* File failed to upload - continue */
if($upload === FALSE) continue;
/* Get the data about the file */
$data = $this->upload->data();
$uploadedFiles[$i] = $data;
/* If the file is an image - create a thumbnail */
if($data['is_image'] == 1) {
$configThumb['source_image'] = $data['full_path'];
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
}
$image['raw'] = $data['raw_name'];
$image['ext'] = $data['file_ext'];
$image['newsid'] = $_POST['newsid'];
$image['description'] = $_POST['description'][$i];
$this->db->insert('multipics', $image);
}
請注意,上面的代碼使多行插入,我只是需要說明字段數據庫
您是否使用print_r($ _ POST)?是否發佈說明。 – Neo 2013-03-28 09:07:23
是描述發佈[描述] =>數組 ( [0] => GGGG [1] => hhhhhhhhhhhhhh [2] => BBB ) – ktm 2013-03-28 09:14:40
使用$這 - > DB-> last_query(),在$ this-> db-> insert語句之後,正確地生成插入語句。 – Neo 2013-03-28 09:16:37