Codeigniter อยากใส่ do_upload 3 ครั้ง เพื่ออ่านค่าที่อัพโหลดต่างกันใน database
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา Codeigniter อยากใส่ do_upload 3 ครั้ง เพื่ออ่านค่าที่อัพโหลดต่างกันใน database
Codeigniter อยากใส่ do_upload 3 ครั้ง เพื่ออ่านค่าที่อัพโหลดต่างกันใน database
Copy
สวัสดีครับ มือใหม่ครับ
ผมอยากจะใส่ do_upload 3 รอบ เพื่อรับค่าอัพโหลดจาก 3 field upload มาลงยัง Database ให้ต่างกัน ได้อย่างไรบ้างครับ
ตอนนี้ผมติดปัญหาที่ว่า 3 field upload ที่สร้างไว้ มันอัพโหลดเป็นไฟล์เดียวกันครับ
เช่น ที่อยากให้เป็นคือ
ตาราง img1 อัพโหลด 01.jpg
img2 อัพโหลด 02.jpg
img3 อัพโหลด 03.jpg
แบบนี้ครับ
Model ครับ
public function update($value = '')
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('img'))
{
$arr1 = array(
'img_name_th' => $this->input->post('img_name_th'),
'img_subname_th' => $this->input->post('img_subname_th'),
'img_color' => $this->input->post('img_color'),
'img_detail_th' => $this->input->post('img_detail_th'),
'img_price' => $this->input->post('img_price'),
'img_formular_th' => $this->input->post('img_formular_th'),
'img_howto_th' => $this->input->post('img_howto_th'),
'img_ingredients_th' => $this->input->post('img_ingredients_th'),
'img_usage_th' => $this->input->post('img_usage_th'),
'img_name_en' => $this->input->post('img_name_en'),
'img_subname_en' => $this->input->post('img_subname_en'),
'img_detail_en' => $this->input->post('img_detail_en'),
'img_formular_en' => $this->input->post('img_formular_en'),
'img_howto_en' => $this->input->post('img_howto_en'),
'img_ingredients_en' => $this->input->post('img_ingredients_en'),
'img_usage_en' => $this->input->post('img_usage_en'),
'img_typename' => $this->input->post('img_typename'),
'img' => $this->input->post('img'),
'img2' => $this->input->post('img2'),
'img3' => $this->input->post('img3'),
);
$this->db->where('img_id', $this->input->post('img_id'));
$this->db->update('img', $arr1);
$this->session->set_flashdata(
array(
'msginfo' => 'OK',
)
);
redirect('', 'refresh');
} else
{
$data = $this->upload->data();
$filename = $data['file_name'];
$filename2 = $data['file_name'];
$filename3 = $data['file_name'];
$arr = array(
'img_name_th' => $this->input->post('img_name_th'),
'img_subname_th' => $this->input->post('img_subname_th'),
'img_color' => $this->input->post('img_color'),
'img_detail_th' => $this->input->post('img_detail_th'),
'img_price' => $this->input->post('img_price'),
'img_formular_th' => $this->input->post('img_formular_th'),
'img_howto_th' => $this->input->post('img_howto_th'),
'img_ingredients_th' => $this->input->post('img_ingredients_th'),
'img_usage_th' => $this->input->post('img_usage_th'),
'img_name_en' => $this->input->post('img_name_en'),
'img_subname_en' => $this->input->post('img_subname_en'),
'img_detail_en' => $this->input->post('img_detail_en'),
'img_formular_en' => $this->input->post('img_formular_en'),
'img_howto_en' => $this->input->post('img_howto_en'),
'img_ingredients_en' => $this->input->post('img_ingredients_en'),
'img_usage_en' => $this->input->post('img_usage_en'),
'img_typename' => $this->input->post('img_typename'),
'img' => $filename,
'img2' => $filename2,
'img3' => $filename3
);
$this->db->where('img_id', $this->input->post('img_id'));
$this->db->update('img', $arr);
$this->session->set_flashdata(
array(
'msginfo' => 'ทำรายการสำเร็จ',
)
);
redirect('', 'refresh');
}
}
VIEW ครับ
<div class="form-group">
<label for="exampleInputEmail1">
<h4> Image / รูปผลิตภัณฑ์ </h4> (<a href="<?php echo base_url('uploads/' . $doc->img); ?>" target="_blank"> ไฟล์เก่า </a>)
<br>
<a href="<?php echo base_url('uploads/' . $doc->img); ?>" target="_blank"><img src="<?php echo base_url('uploads/' . $doc->img); ?>" width="100px"></a>
</label>
<input type="file" name="img" id="img" >
<div class="form-group">
<label for="exampleInputEmail1">
<h4> Image / รูปผลิตภัณฑ์ </h4> (<a href="<?php echo base_url('uploads/' . $doc->img); ?>" target="_blank"> ไฟล์เก่า </a>)
<br>
<a href="<?php echo base_url('uploads/' . $doc->img2); ?>" target="_blank"><img src="<?php echo base_url('uploads/' . $doc->img2); ?>" width="100px"></a>
</label>
<input type="file" name="img2" id="img2">
</div>
<div class="form-group">
<label>
<h4> Image 2 / รูปผลิตภัณฑ์ 2</h4> (<a href="<?php echo base_url('uploads/' . $doc->img3); ?>" target="_blank"> ไฟล์เก่า </a>)
<br>
<a href="<?php echo base_url('uploads/' . $doc->img3); ?>" target="_blank"><img src="<?php echo base_url('uploads/' . $doc->img3); ?>" width="100px"></a>
</label>
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ