我想在提交表单时同时在codeigniter中更新多个图像,并在Submit上上传新图像。这仅适用于上传新的多个图像 这是我的控制器文件
公共功能product_edit($ product_id){
<tbody>
<% @patients.each do |patient| %>
<tr>
<td><%= patient.first_name %></td>
<td><%= patient.last_name %></td>
<td><%= patient.gender %></td>
<td>
<% if patient.most_recent_surgery %>
<%= patient.most_recent_surgery.to_time.strftime('%d-%m-%Y') %>
<% end %></td>
<td class="centra"><%= link_to t('edit'), edit_patient_path(patient) %></td>
<td class="centra"><%= link_to t('delete'), patient, method: :delete, data: { confirm: 'Eliminazione irreversibile. Continuare?' } %></td>
</tr>
<% end %>
</tbody>
<div style="text-align:center;"><%= paginate @patients %></div>
}
这是我的模特
公共函数updateProduct($ product_id,$ updateData,$ filename,$ sub_category_id,$ category_id){
$data["data"] = $this->Menu_management_model->getCat();
$this->load->view('header',$data);
$category_id= $this->uri->segment(4);
$viewData['data'] = $this->Menu_management_model->getProduct($id='',$product_id);
$viewData['image'] = $this->Menu_management_model->getProductPhoto($id='',$product_id);
$this->load->view('products/product_edit', $viewData);
$updateData = array(
'product_name' => $this->input->post('product_name'),
'product_description'=> $this->input->post('product_description'),
);
if($this->input->post('update_product')){
$sub_category_id= $this->input->post('sub_category_id');
$files = $_FILES;
if(!empty($files['product_photo']['name'])){
$count = count($_FILES['product_photo']['name']);
for($i=0; $i<$count; $i++){
$_FILES['product_photo']['name']= $files['product_photo']['name'][$i];
$_FILES['product_photo']['tmp_name']= $files['product_photo']['tmp_name'][$i];
$_FILES['product_photo']['size']= $files['product_photo']['size'][$i];
$config['upload_path'] = 'assets/uploads/products/';
$config['allowed_types'] = 'jpg|png|jpeg';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload('product_photo');
$fileName = $this->upload->data('file_name');
$images[] = $fileName;
}
$fileName = implode(',',$images);
$update= $this->Menu_management_model->updateProduct($product_id,$updateData,$fileName,$sub_category_id,$category_id);
}
这是我的查看页面,所以请检查并帮助我
$update= $this->db->update('products', $updateData, array('product_id'=>$product_id));
if($filename!='' ){
$filename1 = explode(',',$filename);
foreach($filename1 as $file){
$file_data = array(
'product_photo' => $file,
'product_id' => $product_id,
'sub_category_id'=>$sub_category_id,
'category_id'=>$category_id
);
$update = $this->db->insert('product_images', $file_data);
}
}
return $update?true:false;
}